Does setImmediate
clears existing objects ?
#53048
-
Minimal repro, see line 5 of index.js - https://stackblitz.com/edit/stackblitz-starters-vvyzjf?file=index.js class Zoom {
kid = 5;
hush() {
console.log(this.kid);
}
}
const foo = new Zoom();
foo.kid = 4;
setImmediate(foo.hush); // But, why this is undefined ?
foo.hush(); // this prints 4, which I understand Can anyone kindly explain why this is happening ? I couldn't find any info regarding existing objects in https://nodejs.org/en/learn/asynchronous-work/understanding-setimmediate. |
Beta Was this translation helpful? Give feedback.
Answered by
avivkeller
May 19, 2024
Replies: 1 comment
-
It has nothing to do with setImmediate, it has to do with the function not being bound. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
arkapratimc
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It has nothing to do with setImmediate, it has to do with the function not being bound.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind