loading...

Javascript object literal syntax I had never seen

github logo ・1 min read

I encountered the following code when I was working through meteor tutorial.

{
  'submit .new-task'(event) {
    // some code here
  },
}

I was very confused because I had never seen an object literal that contains some string followed by an anonymous function. After I read the MDN web docs about object initializer, I know that the code above is equivalent to the following:

{
  'submit .new-task': function(event) {
    // some code here
  },
}

The syntax looks very odd to me maybe because I am simply not got used to it.

twitter logo DISCUSS
Classic DEV Post from Feb 16

What Do You Find Difficult about SQL and Databases?

What Do You Find Difficult about SQL and Databases?

hitochan profile image