Skip to content
New issue

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' points to Window rather than custom element when called through setTimeOut() #1853

Closed
aravind901 opened this issue Jun 12, 2015 · 3 comments

Comments

@aravind901
Copy link

After calling a function through setTimeOut inside a Polymer element, 'this' no longer points to the custom element but to the window. Demo below.

http://jsbin.com/hehafo/2/edit?html,console,output

@pvmart
Copy link

pvmart commented Jun 12, 2015

use

setTimeout(this.delayed.bind(this),100);

or

this.async(this.delayed,100);

instead

@ghost
Copy link

ghost commented Jun 12, 2015

Third method:

setTimeout(function() {
    this.delayed();
}.bind(this), 100);

@ebidel
Copy link
Contributor

ebidel commented Jun 12, 2015

Yep, this is what async() is for. If you want to use setTimeout, you'll need to bind this. Just scoping ftw!

@ebidel ebidel closed this as completed Jun 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants