A detailed description of the call function

Source: Internet
Author: User

Because recently to the end of the final, but also to prepare six levels, to prepare a little more examinations, in fact, is to make lazy.

Today still a little remorse, or to learn, write something, not to say nonsense, directly write.

------------------------I'm a great dividing line-----------------------------------------------------------------

Today in the front-end group saw a

Dmitry Baranovskiy's Blog contains an article (link) with five small pieces of code to test the understanding of JavaScript's core, closures, and scopes.

Then there were some problems, but most of them were solved.

The last one, the call function, let me react for a while, and then I thought I hadn't seen it. )

I went to Baidu, see the official explanation:

The all method invokes one method of an object, replacing the current object with another object. Call ([thisobj[,arg1[, arg2[,   [,. ArgN]]]) parameter thisobj Optional. The object that will be used as the current object. Arg1, Arg2,  , argn options available. The method parameter sequence will be passed. Indicates that the call method can be used to invoke a method in place of another object. The call method can change the object context of a function from the initial context to a new object specified by Thisobj. If the Thisobj parameter is not provided, then the Global object is used as the thisobj.

I'm bluffing, what the heck, suddenly I think this is not inheritance.

function A (name) {this. name=name; this. show=function() {            alert ("I am" +this. name);                }    }        function B (name) {this. Name=name;a.call (thisvar  New B (' B '); B1.show ();

Popup result "I am B"

There is no Show method in B.

Direct is the inheritance we say.

Read a lot of the blog is said to be replaced, said a bit around can not really understand, I think according to my inheritance understanding is still very correct.

There are multiple inheritance, I do not know whether my understanding is a bit biased.

functionClass1 () { This. Name =function() {alert ("Class1 Method name ()"); }}  functionClass2 () {Class1.call ( This);//to implement Class2 inheritance Class1 This is the current object Class2. }  varCL =NewClass2 (); Cl.name ();//Class2 inherits the Class1,class2 is the parent class. Calling a method of the parent class  //another way to implement inheritance is to use an inheritance function specifically to implement inheritance.  functionExtend () {Class2.call ( This); Class1.call ( This);}

and apply is out of the scope of this article.

---------------------I'm a great dividing line----------------------------------------------------------------------

See you next time, ECMAScript.

And his way of inheriting.

A detailed description of the call function

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.