js中的this

本篇文章会不定时更新

1. call/apply 与this

call和apply 改变this的指向。区别是call是扁平化的传参,一个个传进去,而apply是作为一个数组传入。

2.bind方法与this

bind方法ie9+支持

    function f(){
        return this.a;
    }
    var g = f.bind({a:"test"});
    console.log(g());
    var o = {a:37,f:f,g:g};
    console.log(o.f(), o.g());  // 37  test 
// g = f.bind({a:"test"})
原文地址:https://www.cnblogs.com/morongwendao/p/7055261.html