function Class1 ()
{
THIS.name = function () {
Alert ("Class1 Method name ()");
}
}
function Class2 ()
{
Class1.call (this);//To implement Class2 inheritance Class1 This is the current object Class2.
}
Now you can see if the implementation inherits:
var cl = new Class2 ();
Cl.name ();//class2 inherits Class1,class2 is the parent class. Calling a method of the parent class
Notice the difference between call () and apply (): the same function. The second parameter has a different form. Call passes multiple parameters, which are in any form. The second argument of apply must be an array form.
It's best to understand them in code:
A.call (b,2,3); ==> a.apply (b,[2,3]);//Array form incoming
Is the use of the Apply parameter is an array of attributes. The implicit parameters of the binding function are automatically saved in the arguments array. In this way, use the Apply method:
This.initialize.apply (this, arguments);
You can directly pass in the arguments array of the current function as the second parameter of apply, without a conversion.
JS-based spoofing Inheritance call () method and the Apply () method