Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does colon do in a javascript function parameter

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?

like image 786
Mariksel Azemaj Avatar asked Jun 03 '15 04:06

Mariksel Azemaj


1 Answers

'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.

like image 61
Christopher Bradshaw Avatar answered Oct 04 '22 18:10

Christopher Bradshaw