This is detailed in JavaScript

Source: Internet
Author: User

Objective

This

This is detailed in JavaScript

This detailed

  

How many cases does this point to? How is human control?

"Who calls This,this point to who!!" 】

"This point, do not care where this is written!! Only care about the function that contains this, who calls!! 】

① through () direct call, this point to Window func ();

The ② object. The function call, this points to the current object. Obj.func () Div.onclick = function () {}

③ array subscript called, this points to the current array [func,1,2,3]---àarr[0] ();

④ the callback function for all built-in functions, this points to window SetTimeOut (function () {},1000);

Human control:

The ⑤ is called by the New keyword, which points to the empty object that is newly created. Var obj = new func () {} this-obj

⑥ is called by call, apply, bind and this points to the object we specify.

Func.call (obj, parameter one, parameter 2, Parameter 3 ....) )

Func.allply (obj,[parameter one, parameter 2, Parameter 3 ....) ])

Func.bind (obj) (parameter I, parameter 2, parameter 3) var f = func.bind (obj). f (...);

This is detailed in JavaScript

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.