<分区>
我有一个带有名为“getHtml(elem)”的函数的对象,我想在 $.each 遍历数组时访问它。我知道“this”指的是 $.each 迭代中的元素,那么如何访问对象的函数呢?
例如:
MyObject.prototype.doSomething = function() {
var results = this.getElements(); //returns this object's array of objects
var html;
var elems = [];
var elem;
$.each(results, function(index, value) {
elem = $(this); //refers to the object returned in the $.each function
html = this.getHtml(elem); //doesn't work, this doesn't refer to this object
elems.push(html);
});
},
我得到的错误是:Uncaught TypeError: this.getHtml is not a function
我试图阅读 bind(),但我不明白如何使用它。如何在 $.each 中调用对象的函数?