Javascript question about "this" in function(){}

var self=this



in this code why is the self variable crucial? why cant i just use this?

Because in JS function has its own this, so if you want to have “higher” this you should save it in variable as in code you provided.

You also can use arrow functions to solve this issue, arrow functions haven’t own this:

this.content.getComponent(cc.Animation).scheduleOnce((event) => {
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.