-
Notifications
You must be signed in to change notification settings - Fork 48
Using arrow functions
Vadim Dyachenko edited this page Jun 10, 2022
·
1 revision
2.3 function literals are cool, but what if you could have them shorter?
(pairs of what you can write instead of what)
var f = () => { print("hi!") };
var f = function() { print("hi!") }
var f = () => ;print("hi!"); // alt. - single-statement without curly brackets
var f = function() { print("hi!") }
var f = () => 1;
var f = function() { return 1; }
var f = (a, b) => a + b;
var f = function(a, b) { return a + b; }
Argument types and optional arguments are supported.
- Smart auto-completion
- Types
- JSDoc tags (incl. additional ones)
- @hint tag (mostly 2.3)
- `vals: $v1 $v2` (template strings)
- #args (pre-2.3 named arguments)
- ??= (for pre-GM2022 optional arguments)
- ?? ?. ?[ (pre-GM2022 null-conditional operators)
- #lambda (pre-2.3 function literals)
- => (2.3+ function shorthands)
- #import (namespaces and aliases)
- v:Type (local variable types)
- #mfunc (macros with arguments)
- #gmcr (coroutines)