JavaScript 之 call,bind,apply 方法及 this 的用法辨析

黄琦雲 at 
概述 JavaScript 函数中的三个方法.call(), .apply(), .bind(),总体来说主要功能就是改变函数中 this 关键字的指向,因为 this 默认指向当前环境的对象;例如:var obj = { name: 'Knight', getName: function() { // this 指向 obj 对象 console.log(this.name); }}obj.getName(); // 'Knight'call().call() 可以用于改变 this 值的指向,例如:this.name = 'Knight'; /……