Javascript 绑定函数没有原型
从 使用Function.prototype.bind创建的函数对象没有 prototype属性或[[Code]]、[[FormalParameters]]和 [[Scope]]内部属性 听起来好像我不能做那样的事情(简单的例子)Javascript 绑定函数没有原型,javascript,Javascript,从 使用Function.prototype.bind创建的函数对象没有 prototype属性或[[Code]]、[[FormalParameters]]和 [[Scope]]内部属性 听起来好像我不能做那样的事情(简单的例子) 为什么会受到限制?有什么陷阱吗?这是因为bind包装了您的函数,插入了这个。再包装一次就不行了 它是这样的: const persone = { name: 'Hello World', getName(){ return this.name; }
为什么会受到限制?有什么陷阱吗?这是因为bind包装了您的函数,插入了这个。再包装一次就不行了 它是这样的:
const persone = {
name: 'Hello World',
getName(){
return this.name;
}
};
const cat = {
name: 'Cat'
}
const dog = {
name: 'Dog'
}
//its like doing this:
var methodNoThis = personne.getName;
var methodCatThis = function(){ return methodNoThis.apply(cat);
var methodDogOnCatThis = function(){ return methodCatThis.apply(dog);
文档
它还声明:
bind()函数创建一个新的绑定函数(BF)。BF是一个外来函数对象(来自ECMAScript 2015的术语),它包装了原始函数对象。调用BF通常会导致其包装函数的执行。其绑定会包装您的函数,插入此函数。再包装一次就不行了 它是这样的:
const persone = {
name: 'Hello World',
getName(){
return this.name;
}
};
const cat = {
name: 'Cat'
}
const dog = {
name: 'Dog'
}
//its like doing this:
var methodNoThis = personne.getName;
var methodCatThis = function(){ return methodNoThis.apply(cat);
var methodDogOnCatThis = function(){ return methodCatThis.apply(dog);
文档
它还声明:
bind()函数创建一个新的绑定函数(BF)。BF是一个外来函数对象(来自ECMAScript 2015的术语),它包装了原始函数对象。调用BF通常会执行其包装函数。谢谢,但我知道如何避免它。问题是,为什么它会受到限制?有没有人犯了这个愚蠢的错误?再次使用此方法包装该方法将没有任何效果,并且只能是开发人员银行的错误/bug,但我知道如何避免它。问题是,为什么它会受到限制?有没有人犯了这个愚蠢的错误?再次使用此方法包装该方法将没有任何效果,并且只能是开发人员的错误/bug