[{"data":1,"prerenderedAt":44},["ShallowReactive",2],{"blog-post-2016-07-04-js-e4-b8-ad-e7-9a-84-bind-e4-b8-8e-call":3},{"id":4,"title":5,"body":6,"categories":30,"date":32,"description":12,"extension":33,"meta":34,"navigation":35,"path":36,"seo":37,"stem":38,"summary":39,"tags":40,"__hash__":43},"blog\u002Fblog\u002Fjs-e4-b8-ad-e7-9a-84-bind-e4-b8-8e-call.md","JS 中的 bind 与 call",{"type":7,"value":8,"toc":27},"minimark",[9,13,24],[10,11,12],"p",{},"JS 中调用方法或函数时，有时候需要变更 this 的指向，通常我们会使用 call\u002Fapply，而 bind 也可以改变 this 的指向，那么他们有什么区别呢？ 简单地说，call\u002Fapply 是改变 this 指向时立即调用，而 bind 只是绑定了新的指向，返回的依然是一个 function。举例说明：",[14,15,20],"pre",{"className":16,"code":18,"language":19},[17],"language-text","var foo = {\n  a: 1,\n  b: 2,\n  add: function(before, after){\n    return before + this.a + this.b + after;\n  }\n},\nbar = {\n  a: 3, \n  b: 4\n};\n\u002F\u002F call\nfoo.add.call(bar, 'before', 'after'); \u002F\u002F #1\n\u002F\u002F bind\nfoo.add.bind(bar, 'before', 'after')(); \u002F\u002F #2\nfoo.add.bind(bar)('before', 'after'); \u002F\u002F #3\n","text",[21,22,18],"code",{"__ignoreMap":23},"",[10,25,26],{},"#1，#2，#3 将会返回一样的值。",{"title":23,"searchDepth":28,"depth":28,"links":29},2,[],[31],"Development","2016-07-04T19:14:23+08:00","md",{},true,"\u002Fblog\u002Fjs-e4-b8-ad-e7-9a-84-bind-e4-b8-8e-call",{"title":5,"description":12},"blog\u002Fjs-e4-b8-ad-e7-9a-84-bind-e4-b8-8e-call","JS 中调用方法或函数时，有时候需要变更 this 的指向，通常我们会使用 call\u002Fapply，而 bind 也可以改变 this 的指向，那么他们有什么区别呢？ 简单地说，call\u002Fapply 是改变 this 指向时立即调用，而 bi…",[41,42],"front","js","tAsWiFfuV8ZOdTixYf5XVblsEEbGwYBODBzm1_vs2Zs",1795177974330]