Created
August 4, 2015 01:04
-
-
Save thenormalsquid/9674c6c45220f2e93b35 to your computer and use it in GitHub Desktop.
arrow func
This file contains hidden or 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 asyncFunction = (param, callback) => { | |
window.setTimeout(() => { | |
callback(param); | |
}, 1); | |
}; | |
var o = { | |
doSomething: function () { | |
// Here we pass `o` into the async function, | |
// expecting it back as `param`. | |
// | |
// Because this arrow function is created within | |
// the scope of `doSomething` it is bound to this | |
// lexical scope. | |
asyncFunction(o, (param) => { | |
console.log('param === this?', param === this); | |
}); | |
} | |
}; | |
o.doSomething(); // param === this? true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment