Javascript five function call methods, this represents
Source: Internet
Author: User
1. Call A method (the so-called method is A member function in the class, that is, the method). Call:. a (); If method a has this, this points to Class A 2. function call (normal function), call: a (); If method a has this, this is a super global variable pointing to the window... syntaxHighlighter. al 1. method call (the so-called method is A member function in the class, that is, the method). Call:. a (); If method a has this, this points to Class A 2. function call (normal function), call: a (); If method a has this, this is a super global variable pointing to the window object 3. constructor call (object initialization method), call: new a (); If method a contains this, then this is bound to prototype of A's prototype. A is an object, and method a is A method in method a. 4. call. call:. call (); the call method has a specified parameter, that is, the first parameter is the object to which this is bound. a is a method, if a has multiple parameters, it is called as follows:. call (objThis, param1, param2 ,.........); 5. apply call. Call:. apply (); The apply method has a specified parameter, that is, the first parameter is the object to which this is bound. a is a method, if a has multiple parameters, it is called as follows:. apply (objThis, [param1, param2, param3. ......]); ps: The difference between call and apply: Yes. If a method has multiple parameters, call lists the parameters one by one, and apply Concatenates the parameters into an array for calling.
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