Call:
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. To be clear is actually to change the object's internal pointer, that is, to change the object's this point to the content. This is sometimes useful in the object-oriented JS programming process.
Apply
Applies one method of an object, replacing the current object with another object.
If none of the Argarray and Thisobj parameters are provided, then the Global object is used as a thisobj and cannot be passed any parameters.
function Animal (xx) {
This.name= ' Zhu '
This.showname=function (CC,JJ) {
Alert (this.name+cc+ ', ' +jj);
}
alert (THIS.NAME+XX);
}
function Cat ()
{
This.name= ' cat ';
}
var animal=new animal ();
var cat=new cat ();
Animal.call (Cat, ' df ');
THIS.name;
Animal.apply ();
THIS.name;
var zhu=function (name) {this.name=name};
var ben=function (Sex) {this.sex=sex;}
var xi=function (age) {this.age=age;}
var people=function (Name,sex,age,score) {zhu.call (this,name); Ben.call (this,sex); Xi.call (this,age); this.score= Score;}
People.prototype.construction=people;
var p=new people (' Zhao ', ' Male ', ' 11 ', ' 78 ');
Console.log (P.name);
Console.log (P.sex);
Console.log (P.age);
Console.log (P.score);
function Animal (name)
{
This.name=name;
This.showname=function () {alert (this.name);}
}
function Cat (name)
{
Animal.call (This,name);
}
var cat=new cat (' White Cat ');
Cat.showname ();
function Animal () {
This.name= ' Animal ';
This.showname=function (AA) {
alert (THIS.NAME+AA);
}
}
function Cat ()
{
This.name= ' Cat ';
}
var animal=new animal ();
var cat=new cat ();
Animal.showName.call (cat, ' KK ');
function Add (A, B)
{
alert (A+B);
}
function Sub (A, b)
{
Alert (A-B);
}
Add.call (sub,4,9);
function Base () {this.member= "a People"; This.method=function () {window.alert (This.member);}}
function Extend ()
{
Base.call (this);
Window.alert (member);
Method ();
Window.alert (This.method);
}
Extend ();
var classa={create:function () {return function () {this.cc.apply (this,arguments); this.ee.apply (this,arguments);}}} var vehicle=classa.create (); Vehicle.prototype={ee:function (UU,KK) {alert ("0")}, Cc:function (type,xx) {this.type=type;this.xx=xx;},showself: function () {alert (this.xx+ "This +vehile" +this.type);}} var moto=new vehicle ("Moto", "lll"); Moto.showself ();
var a= "JJJ"; var b= "abc", var func=new function () {this.a= "func"; this.b= "BBB";} var myfunc=function (x) {var a= "myfunc"; this.b= "KKK"; alert (THIS.A); alert (this.b); }; Myfunc.call (func, "Var");
JavaScript call apply