クラス(モジュール)(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)