-
-
Save hkdnet/0566c9eb040cb4d1b7c955097bf1e5e2 to your computer and use it in GitHub Desktop.
arrow function examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arguments = 42; | |
var arr = () => arguments; | |
arr(); // 42 | |
function foo() { | |
var f = (i) => arguments[0] + i; // foo's implicit arguments binding | |
return f(2); | |
} | |
foo(1); // 3 | |
function foo() { | |
var f = (...args) => args[0]; | |
return f(2); | |
} | |
foo(); // 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arguments = [1, 2, 3]; | |
var arr = () => arguments[0]; | |
arr(0); // 1 | |
function foo(n) { | |
var f = () => arguments[0] + n; | |
return f(10); | |
} | |
foo(1); // 2 | |
function foo(n) { | |
var f = (...args) => args[0] + n; | |
return f(10); | |
} | |
foo(1); // 11 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment