Skip to content

Instantly share code, notes, and snippets.

@thenormalsquid
Created August 4, 2015 01:04
Show Gist options
  • Save thenormalsquid/9674c6c45220f2e93b35 to your computer and use it in GitHub Desktop.
Save thenormalsquid/9674c6c45220f2e93b35 to your computer and use it in GitHub Desktop.
arrow func
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