It seems that an object does not have a method to process the data, a method has no object data, so that the two can SquarePants underwater, just fine.
----
A function that uses the properties of another object through its own method to achieve some kind of change or the purpose of outputting data.
2015-5-4--is a function. Call (Object A) the properties of object A will be moving into this function, and will naturally output a value or change something.
==============
Call () and apply () are the own methods that each function contains. It has been mentioned before that a function is a defined object, so when calling a function, this is a call to the current and next variable. If you want to change the domain space where the function executes, you can use call () and apply ().
color = ' red ';
var o = {color: ' Blue '};
function Saycolor () {
Console.log (This.color);
}
Saycolor (); Red
Saycolor.call (this); Red
Saycolor.call (o); Blue = = = Popular understanding is to connect objects, let their own methods. The money to help people to let others play.
/////////////////////////////////////////////////////////////////////
http://www.zhihu.com/question/20289071
Http://www.cnitblog.com/yemoo/archive/2007/11/30/37070.aspx
=================
LZ to understand the existence of call and apply the reason, to remember a bit:
In JavaScript oop, we often define this:
function Cat () {
}
cat.prototype={
Food: "Fish",
Say:function () {
Alert ("I Love" +this.food);
}
}
var blackcat = new Cat;
Blackcat.say (); But if we have an object Whitedog = {food: "Bone"}, we do not want to redefine it say method, then we can use call or Apply with Blackcat say method: BlackCat.say.call (White
BlackCat.say.call (Whitedog);
So, you can see that call and apply are meant to change this dynamically, and when an object does not have a method, but the others, we can use call or apply to manipulate other objects.
The DOM node chosen by document.getElementsByTagName is a type of array that is similar to array. It cannot apply methods such as Push,pop under the array. We can do this by:
var domnodes = Array.prototype.slice.call (document.getElementsByTagName ("*"));
This allows the domnodes to apply all the methods under the array.
Call Apply JS