我有打電話的原型方法,它返回一個問題:JavaScript對象原型類型錯誤:...是不確定的
TypeError: this.backgroundImagesReplace(...) is undefined
this.backgroundImagesReplace(data)
我的代碼如下所示:
var Template = function() {};
Template.prototype = {
backgroundImagesReplace : function(data) {
var defer = $.Deferred();
// some code that resolves the deferred object
defer.resolve(data);
},
replace : function(data, callback) {
this.backgroundImagesReplace(data)
.done(this.replaceContent)
.done(this.replaceElement)
.done(this.replaceAttribute)
.done(systemObject.executeCallBack(callback));
},
init : function() {
this.replace([], function() {
console.log('here');
});
}
};
var TemplateObject = new Template();
TemplateObject.init();
任何想法可能會導致它?
你需要返回'defer.promise()' –
感謝澳航 - 就是這樣! –
@ArunPJohny:true - 當直接返回「Deferred」對象「起作用」時,返回一個'Promise'可能更好。 –