- 2020-03-30 01:45:53
I. description of call and apply
Foo. call(this, arg1,arg2,arg3) == foo.apply(this, arguments) == this.foo(this, arg2,arg3);
3. Similarities: the two methods have exactly the same effect.
4. Differences: the parameters passed by the method are different.
Two, example code
3. Code interpretation (that is, explain the apply and call functions)
1. The example code defines two functions A and B, in which A contains the flag attribute and tip attribute (this attribute assigns A function), and in which B has A flag attribute.
2. Create objects A and B of A and B respectively.
3. Whether a.t IP. Call (b); And a.t IP. Apply (b); I'm going to pop up B.
4. It can be seen from the results that both call and apply can make B object call the tip method of A object and modify the current action object of this.