var name = 'window'
function test() {
console.log(...arguments)
console.log(this.name)
return 'test function'
}
Function.prototype.lBind = function (target) {
var _argu = Array.prototype.slice.call(arguments, 1)
var _this = this
return function () {
_argu = _argu.concat(Array.prototype.slice.call(arguments))
Object.defineProperty(target, '_fn', {
enumerable: false,
writable: false,
configurable: true,
value: _this
})
var result = target._fn(..._argu)
delete target._fn
return result
}
}
Function.prototype.lCall = function (target) {
var _argu = []
for (var i in arguments) {
if (i !== '0') _argu.push(arguments[i])
}
var _this = this
Object.defineProperty(target, '_fn', {
enumerable: false,
writable: false,
configurable: true,
value: _this
})
var result = target._fn(..._argu)
delete target._fn
return result
}
Function.prototype.lApply = function (target) {
var _argu = arguments[1] || []
var _this = this
Object.defineProperty(target, '_fn', {
enumerable: false,
writable: false,
configurable: true,
value: _this
})
var result = target._fn(..._argu)
delete target._fn
return result
}
console.log(test.lApply({ name: 'lApply'}, [1, 2, 3]))
console