SetTimeout problem Solving method in JavaScript _javascript skills

Source: Internet
Author: User
See a problem, probably like this.
Copy Code code as follows:

Name = ' Out of '
foo = function () {
this.name = ' Xxoo ';
}
Foo.prototype.say = function () {
Console.log (this.name);
}
f = new Foo ();
F.say (); This will output xxoo.
SetTimeout (F.say, 500); This will output out of

This is a pit, JavaScript's this is generated at the time of the call, but also related to the context. So solve it. I tested it and used call.
Copy Code code as follows:

Settimeout.call (foo (), F.say, 500)

Some solutions on the Internet

This point problem in settimeout in JS

Use timer in JavaScript

In the end, we have to understand the question.

One day we'll get to the point.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.