我看到的實現函數綁定環境的方法是:function bind(fn,context){ return function(){ return fn.apply(context,arguments);
}
}我對這個閉包很疑惑,如果不搞閉包,直接:function bind(fn,context){ return fn.apply(context);
}不也是能實現綁定嗎,設置我連bind函數也不要,在需要綁定的時候直接寫:fn.apply(context);所以這個閉包的作用是什么,除了方便傳參,還有什么特殊的作用嗎?先謝過大家了。
JavaScript中函數綁定實現的問題
FFIVE
2018-09-15 10:49:10