3 ms·
Just in case, in Sciter script that could be written simply as: element.animate { duration: 300ms, completion: () => this.remove() } Explanati
by c-smile 6y ago
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.
- logicprog 6y agoHashmap 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.
- lioeters 6y agoI 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")