JS usage also has a very good but some abstract usage--call and apply, today I want to summarize briefly:
var ob1={ //Object OB1 Name: "Ob1", func1:function (a,b,c) { alert (this.name+a+b+c); } } var ob2={//Object OB2 Name: "Ob2", func2:function () { alert (this.name); } } Ob1.func1.call (OB2, "1", "2", "3"); Ob1123,call Let object B call the func1 of a, pointing to a pointer to B, so that B can be a func1 to access to their own properties Ob2.func2.call (OB1); Ob1 ob1.func1.apply (ob2,[1,2,3]);//ob2123 ob2.func2.apply (OB1);//ob1
"Ob2.func2.call (OB1)" is equivalent to "OB1.FUNC2 ()", in fact Ob1 does not have fun2, but call can help him to borrow from the OB2 and the pointer points to the OB1,FUNC2 in this point to its caller ob1, The Name property of the output ob1. Apply is the same as call usage, but the arguments are passed in different ways.
You may feel a bit around, wondering where the convenience of this writing is. Let's briefly summarize when it should be used, when object 2 wants to invoke the method in object 1, so that when writing less code, Object 1 typically has similar properties to Object 2, similar in type or identical.
Call and apply basic usage tell you