객관적으로은 Backbone.Model
을 사용하는 것으로 잘못되었지만, 어쨌든 비린내 느낌입니다. 모델에는 "서비스"또는 "유틸리티"유형 클래스에 속하지 않는 여분의 수화물이 함께 제공됩니다.
대신 Backbone Model-View-Collection-Router 패러다임에 맞지 않는 기능을 위해보다 일반적인 범용 이벤트 클래스를 정의했습니다. 이 extend
에드 될 수 있다는 점에서
define(['backbone', 'underscore'], function(Backbone, _) {
var Class = function() {
this.initialize.apply(this, arguments);
};
//give Class events and a default constructor
_.extend(Class.prototype, Backbone.Events, {initialize: function() {}});
//copy the extend feature from one of the backbone classes
Class.extend = Backbone.Model.extend;
return Class;
});
클래스는 다른 백본 객체처럼 동작, 그 인스턴스는 initialize
생성자 메서드를 가지고 있고 이벤트를 지원합니다. 귀하의 예 중 하나 인 현지화 서비스는 같은 것을 볼 수 있었다 다음에 http://addyosmani.github.com/backbone-fundamentals/
오른쪽 : 애디 오스 마니에 의해 "Backbone.js 응용 프로그램 개발"무료 backbone.js 전자 책이 있습니다
var LocalizationService = Class.extend({
initialize: function(url) {
this.url = url;
this.fetch();
},
fetch: function({
var self = this;
$.ajax({
url:this.url,
success: function(response) {
self.response = response;
self.trigger('fetch:complete', self, response);
//etc...
}
});
}
});
큰 질문! 이것은 내가 찾고 있었던 바로 그 것이다. 그것이 닫힌다는 어리 석다. – Kieveli