| |
| /* call和apply都可以理解为是函数自身的方法 |
| 第一个参数代表了 接下来this所代表的对象 */ |
| /* f.call(obj1) 会执行f这个方法 */ |
| // console.log( f.call(obj1) ) /* this=>obj1 */ |
| // console.log( f.call(obj2) ) /* this=>obj2 */ |
| |
| // console.log( f.apply(obj1) ) /* this=>obj1 */ |
| // console.log( f.apply(obj2) ) /* this=>obj2 */ |
| |
| /* call和apply的区别 */ |
| /* 使用call方法来传参 一个一个的传参 */ |
| // console.log( f.call(obj1,'bmw','tangc') ) /* this=>obj1 */ |
| /* 使用apply方法来传参 需要传一个数组 数组里面的第一个就对应了f函数里面的 |
| 第一个参数,数组里面的第二个就对应了f函数里面的 |
| 第二个参数 */ |
| // console.log( f.apply(obj1,['bmw','tangc']) ) |
| |
| function Person(){ |
| this.foot = 2 |
| } |
| function Student(){ |
| Person.call(this) |
| } |
| |
| console.log( new Student() ); |