Function.prototype.bindX = function() {
let self = this
let [thisArg, ...args] = arguments
return function() {
self.apply(thisArg, [...args, ...arguments])
}
}
複製代碼
Function.prototype.callX = function () {
let [thisArg, ...args] = arguments
let fn = Symbol()
thisArg[fn] = this
let result = thisArg[fn](...args)
delete thisArg[fn]
return result
}
複製代碼
Function.prototype.applyX = function () {
let [thisArg, args] = arguments
let fn = Symbol()
thisArg[fn] = this
let result = thisArg[fn](...args)
delete thisArg[fn]
return result
}
複製代碼
說它多有用吧,真的沒多大意義,裏面僅僅是實現最基礎的功能,僅僅是我的拿來玩的,退一萬步講,即使在某種狀況下沒有原生的bind,call,appay的支持,項目中也會用別人已經寫好的。數組
若是硬要說些什麼,那應該是js真的愈來愈好用了,要善加利用(⊙o⊙)哦bash
我的的一些感悟app
您能夠查看MDN上比較權威的實現函數
還有幾個疑問,請教一下你們ui