JS apply用法总结和使用场景实例分析
本文实例讲述了JS apply用法总结和使用场景。分享给大家供大家参考,具体如下: apply是绑定this到指定函数或类,也可以说把函数或者类的方法和属性给到当前作用域。 1,使用apply实现继承 function A(name, age){ this.name = name; this.age = age; } function B(name, age, time){ A.apply(this,[name]) //这里的name必须加上[] } const b = new B('继承'); console.log(b) 2,使用apply实现
下载地址
用户评论