We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This is the origin sample code, the result is 1.
function myFunc() { this.myVar = 0; setTimeout(() => { this.myVar++; console.log(this.myVar); }, 0); } myFunc(); // 1
And the following code has the same reuslt 1.
function myFunc() { this.myVar = 0; setTimeout(function() { this.myVar++; console.log(this.myVar); }, 0); } myFunc(); // 1
And i think use an object manner write this example maybe better? Like this:
myVar = 123; var object= { myVar: 0, f: function () { setTimeout(() => { this.myVar++; console.log(this.myVar); }, 0); } } object.f(); // 1
And this is the comparing code:
myVar = 123; var object= { myVar: 0, f: function () { setTimeout(function() { this.myVar++; console.log(this.myVar); }, 0); } } object.f(); // 124
The text was updated successfully, but these errors were encountered:
No branches or pull requests
This is the origin sample code, the result is 1.
And the following code has the same reuslt 1.
And i think use an object manner write this example maybe better? Like this:
And this is the comparing code:
The text was updated successfully, but these errors were encountered: