最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What does colon do in a javascript function parameter - Stack Overflow

programmeradmin2浏览0评论

I saw in a javascript code written by a young guy this function

function foo(e:MouseEvent){
   ...
}

I want to know what does e:MouseEvent do?

I saw in a javascript code written by a young guy this function

function foo(e:MouseEvent){
   ...
}

I want to know what does e:MouseEvent do?

Share Improve this question edited Jan 28, 2021 at 10:26 Mariksel Azemaj asked Jun 3, 2015 at 4:42 Mariksel AzemajMariksel Azemaj 5928 silver badges21 bronze badges 7
  • 3 It's called a syntax error. – Ram Commented Jun 3, 2015 at 4:43
  • 1 @Vohuman what does it mean – Mariksel Azemaj Commented Jun 3, 2015 at 4:44
  • It breaks your script. That's not valid JavaScript. – Ram Commented Jun 3, 2015 at 4:46
  • 3 Are you sure it is JavaScript, and not TypeScript, or Flow, or something with types that compiles to JavaScript? – elclanrs Commented Jun 3, 2015 at 4:48
  • It smells like one of those pseudo languages. It can be read as this parameter is an instance of MouseEvent constructor. – Ram Commented Jun 3, 2015 at 4:51
 |  Show 2 more comments

1 Answer 1

Reset to default 23

'e:MouseEvent' is a named parameter with a type declaration in typescript. A colon is used in typescript parameters to bind a parameter to a specific type which, in this case, is type 'MouseEvent'.

e is often used as the parameter name for a javascript event. Given the type it's likely a function that responds to a click event.

You can read more details about the syntax for it under the 'Function Types' heading of TypeScript's official documentation: https://www.typescriptlang.org/docs/handbook/functions.html.

发布评论

评论列表(0)

  1. 暂无评论