Call Usefulness: Assign all properties and methods of B to target object A dynamically, noting that a does not have these properties and methods in itself!
The call syntax is: B.call (THISOBJ,ARG1,ARG2,ARG3)
Explanation: Thisobj is the target object (the target object to which the method property is assigned), ARG1,ARG2,ARG3 is a parameter, can be one, or it can be multiple
Scenario One: Only the first parameter of call (that is, the target object) is preserved
varb =function() { This. Name = "123"; This. Message =function(obj) {console.log (obj); }; This. ShowName =function(obj) {console.log (obj); };};varA = {};//define an empty object aB.call (a);//assign all properties and methods of B to object a dynamically, and note that a does not have these properties and methods in itself!A.message ("Displays the message specified by a");//displays the message specified by aA.showname ("Show information specified by a");//Displays the show information specified by aConsole.log (A.name);//123
Understanding of the call () method in JavaScript (and comparing the Apply method)