const _new = function (Fn, ...args) {
if (typeof Fn !== 'function') {
throw new TypeError('_new function TypeError: the first param must be a function')
}
const obj = Object.create(Fn.prototype)
const res = Fn.apply(obj, args)
if ((typeof res === 'object' && res !== null) || typeof res === 'function') {
return res
}
return obj
}
Function.prototype._call = function (context = window, ...args) {
const fn = Symbol()
context[fn] = this
const result = context[fn](...args)
delete context[fn]
return result
}
Function.prototype._apply = function (context = window, args) {
const fn = Symbol()
context[fn] = this
const result = context[fn](...args)
delete context[fn]
return result
}
Function.prototype._bind = function (context = window, ...args) {
if (typeof this !== 'function') {
throw new Error('Function.prototype.bind - what is trying to be bound is not callable')
}
const self = this
const fbound = function (...innerArgs) {
self.apply(this instanceof self ? this : context, args.concat(innerArgs))
}
fbound.prototype = this.prototype
return fbound
}