Я смотрел на шаблоны Backbone-requireJS в GitHub, я вижу два разных типа реализаций.
https://github.com/david0178418/BackboneJS-AMD-Boilerplate/blob/master/src/js/views/viewStub.js имеет следующее как viewStub:
function() {
"use strict";
define([
'jqueryLoader',
'underscore',
'backbone',
],
function($, _, Backbone) {
return Backbone.View.extend({
template : _.template(/*loaded template*/),
initialize : function() {
this.render();
},
render : function() {
$(this.el).append(this.template(/*model/collection*/));
return this;
}
});
}
);
})();
Принимая во внимание, что заглушка с другой стороны
https://github.com/jcreamer898/RequireJS-Backbone-Starter/blob/master/js/views/view.js имеет следующее:
define([
'jquery',
'backbone',
'underscore',
'models/model',
'text!templates/main.html'],
function($, Backbone, _, model, template){
var View = Backbone.View.extend({
el: '#main',
initialize: function(){
this.model = new model({
message: 'Hello World'
});
this.template = _.template( template, { model: this.model.toJSON() } );
},
render: function(){
$(this.el).append( this.template );
}
});
return new View();
});
Мой вопрос здесь:
Почему в первом примере вокруг всего модуля RequireJS выполняется самовыполняющаяся функция?