Function.prototype.bind = function(){ var self = this, // 保存原函數 context = [].shift.call( arguments ), // 需要綁定的 this 上下文//***這行代碼不不理解*** args = [].slice.call( arguments ); // 剩余的參數轉成數組 return function(){ // 返回一個新的函數 return self.apply( context, [].concat.call( args, [].slice.call( arguments ) ) ); // 執行新的函數的時候,會把之前傳入的 context 當作新函數體內的 this // 并且組合兩次分別傳入的參數,作為新函數的參數 } }; context = [].shift.call( arguments ); 這代碼有點不理解
看行代碼,不大懂!
慕容森
2018-09-04 08:10:56