Hacker News new | past | comments | ask | show | jobs | submit login

Just in case, in Sciter script that could be written simply as:

   element.animate {
     duration: 300ms,
     completion: () => this.remove()
   }
Explanation, this syntax construct

   nmtoken {...}
is just a sugar for this:

   nmtoken ({...})
And that is good old function call with single object/map literal as a sole argument.

By the way this construct can be added to JavaScript without breaking existing code.




Hashmap literals are the right approach to named arguments and functions-as-control-structures IMHO. Ruby does this too IIRC. It's great because it re-uses existing syntax and semantics instead of adding edge cases. You can even add syntax sugar like you just demonstrated.


I like this syntax improvement. It simplifies the very common case of calling a function with an object as a way to pass named arguments.

It reminds me, I believe Lua has similar syntax sugar that works with tables as well as strings.

  fn "hello"
is equivalent to

  fn("hello")




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: