美文网首页前端拾遗
javascript -- apply

javascript -- apply

作者: 就叫初九吧 | 来源:发表于2017-03-10 13:56 被阅读0次

apply()方法使用指定的this(作用域)和数组形式的参数调用一个方法
functionName.apply(this[,[ar1, ar2, ...]])

apply通过指定this(可以是null、undefined、object、原生对象等)将函数的功能给予指定的this

var a = { name: 'a' },
      b = {
            name: 'b',
            say: function(){
              console.info(this.name)
            }
          }
b.say.apply(a) 
结果输出 ===> a

相关文章

网友评论

    本文标题:javascript -- apply

    本文链接:https://www.haomeiwen.com/subject/augngttx.html