我想了解如何在这种特定情况下使用bind(this):
this.resizeImages(maxcat, this); //this belongs to the Widget Object
Widget.prototype.resizeImages = function(maxcat, self)
{
switch(maxcat)
{
case "firstcase":
self.piePaper.path(activityImages[maxcat]);
break;
}
}
如何使用 bind(this) 并将参数 maxcat 一起传递,而不是使用两个参数?
我想要一个这样的方法:
Widget.prototype.resizeImages = function(maxcat)
{
switch(maxcat)
{
case "firstcase":
this.piePaper.path(activityImages[maxcat]); //this belongs to the Widget Object
break;
}
}
我想要这样的东西:this.resizeImages(maxcat).bind(this);
当然它不起作用,这只是举个例子。
最佳答案
试试这个(我知道已经快两年了,但还是回答一下):
this.resizeImages.bind(this, maxcat)();
关于javascript - 使用bind(this)并一起传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34607594/