Skip to content

Instantly share code, notes, and snippets.

@CodHeK
Last active June 8, 2020 16:29
Show Gist options
  • Save CodHeK/b28aaf058876147061efa9f04091cb35 to your computer and use it in GitHub Desktop.
Save CodHeK/b28aaf058876147061efa9f04091cb35 to your computer and use it in GitHub Desktop.
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