Igor Posted November 16, 2021 Share Posted November 16, 2021 Hello! Is it possible to easily set scope without storing additional variables? For example in pixi.js I can do: target.on('event', this.func, this); // this code inside the class. Last argument is scope (instance of class). target.off('event', this.func, this); // no need to set id or store additional variables. Just also specify scope. given that there is a lot of code in classes and often you need to specify the context, I think it's really more convenient, than: tween = gsap.delayedCall(1, this.func.bind(this)); gsap.killTweensOf(tween) // need to store a variable gsap.delayedCall(1, this.func.bind(this)).vars.id = 'id'; gsap.killTweensOf('id') // need to come up with id I would like to see: gsap.delayedCall(1, this.func, this); gsap.killTweensOf(this.func, this); Thanks for help:) Link to comment Share on other sites More sharing options...
OSUblake Posted November 16, 2021 Share Posted November 16, 2021 Hi Igor, I would just bind the method ahead of time, like in the constructor. this.func = this.func.bind(this); ... gsap.delayedCall(1, this.func) Or use an arrow function. gsap.delayedCall(1, () => this.func()); 2 Link to comment Share on other sites More sharing options...
OSUblake Posted November 16, 2021 Share Posted November 16, 2021 Also, you can use a function as a property and there is no need to bind. class Foo { func = () => { console.log("THIS", this) } constructor() { this.msg = "hello" gsap.delayedCall(1, this.func) // works } } 2 Link to comment Share on other sites More sharing options...
Igor Posted November 17, 2021 Author Share Posted November 17, 2021 Thanks for the answer! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now