Stavo guardando i piatti lastre Backbone-requireJS in GitHub, vedo due diversi tipi di implementazioni.C'è una buona ragione per avvolgere una funzione extra immedently-invoked attorno a una definizione del modulo requireJS?
https://github.com/david0178418/BackboneJS-AMD-Boilerplate/blob/master/src/js/views/viewStub.js ha la seguente come 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;
}
});
}
);
})();
considerando che la visione a stub dall'altra boilerplate https://github.com/jcreamer898/RequireJS-Backbone-Starter/blob/master/js/views/view.js ha la seguente:
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();
});
La mia domanda è: Perché esiste una funzione auto-eseguibile attorno all'intero modulo RequireJS nel primo esempio?
@missingno grazie per la modifica! – Karthik