Last active
June 8, 2020 16:29
-
-
Save CodHeK/b28aaf058876147061efa9f04091cb35 to your computer and use it in GitHub Desktop.
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
const obj = { | |
prop: 'Hello', | |
method: function() { | |
const callback = function() { | |
console.log(this.prop + ', World!'); // Hello, World! | |
} | |
setTimeout(callback.bind(this), 2000); | |
} | |
}; | |
obj.method(); | |
/* ------------------------ OR -------------------------------- */ | |
const obj = { | |
prop: 'Hello', | |
method: function() { | |
function inner() { | |
console.log(this.prop + ', World!'); // Hello, World! | |
} | |
const innerBind = inner.bind(this); | |
innerBind(); | |
} | |
}; | |
obj.method(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment