0
我試圖擴展一個類(模塊)(1)Backbone.Collection var MessageCollection.prototype
(2)。我應該如何定義以下模塊才能使其工作
我應該如何定義以下模塊才能使其工作?
(1)
/*global define, setTimeout*/
define([
'underscore'
], function (_) {
"use strict";
return {
startPolling: function() {
this.polling = true;
this.executePolling();
// _.bindAll(this, 'onFetch', 'startPolling', 'stopPolling');
},
stopPolling: function() {
this.polling = false;
},
executePolling: function() {
this.fetch({success : this.onFetch});
},
onFetch: function() {
var self = this;
console.log(this); // undefined
console.log(self); // undefined
if (this.polling) { // Cannot read property 'polling' of undefined
setTimeout(this.executePolling, 1000 * 60 * this.minutes);
}
}
}
return Poll;
});
(2)
/*global define*/
define([
'underscore',
'backbone',
'moment',
'../utils/poller'
], function (_, Backbone, Poller) {
'use strict';
var MessageCollection = Backbone.Collection.extend({
// some code
});
_.extend(MessageCollection.prototype, Poller);
return MessageCollection;
});
var messageCollection = new MessageCollection();
messageCollection. startPolling(); // Cannot read property 'polling'
// of undefined (see the comment on the code)
感謝您的答覆,但是這是不對的,我增加了更多的細節,我的問題。希望這會有所幫助。無論如何'不能讀取未定義的屬性'輪詢',這意味着這不是窗口。 – 2012-07-30 19:14:56
@LorraineBernard:這只是一個想法,哦很好= / – 2012-07-30 19:18:28