We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bind API MDN
// 最简版 function bind(fn, context) { return function () { return fn.apply(context, Array.prototype.slice.call(arguments)) } } // 预置参数 function bind(fn, context) { var args = Array.prototype.slice.call(arguments, 2) return function () { return fn.apply(context, args.concat(Array.prototype.slice.call(arguments))) } } // new操作符,忽略thisArg function bind(fn, context) { var argsPre = Array.prototype.slice.call(arguments, 2) function bindFn() { context = this instanceof bindFn ? this : context const args = argsPre.concat(Array.prototype.slice.call(arguments)) return fn.apply(context || null, args) } bindFn.prototype = fn.prototype return bindFn } // new优化版,不修改原函数的原型对象 function bind(fn, context) { var argsPre = Array.prototype.slice.call(arguments, 2) function Fake(){} function bindFn() { context = this instanceof bindFn ? this : context const args = argsPre.concat(Array.prototype.slice.call(arguments)) return fn.apply(context || null, args) } Fake.prototype = fn.prototype bindFn.prototype = new Fake return bindFn }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
bind API MDN
The text was updated successfully, but these errors were encountered: