Estaba mirando los esquemas de Backbone-requireJS en GitHub, veo dos tipos diferentes de implementaciones.¿Hay una buena razón para envolver una función adicional invocada de forma inmediata alrededor de una definición de módulo requireJS?
https://github.com/david0178418/BackboneJS-AMD-Boilerplate/blob/master/src/js/views/viewStub.js tiene la siguiente como el 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;
}
});
}
);
})();
Mientras que la visión-talón de la otra plancha de caldera https://github.com/jcreamer898/RequireJS-Backbone-Starter/blob/master/js/views/view.js tiene la siguiente:
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();
});
Mi pregunta aquí es: ¿Por qué es Existe una función de autoejecución alrededor de todo el módulo RequireJS en el primer ejemplo?
@missingno gracias por la edición! – Karthik