What's the difference between these two requirejs modules? -
sorry if seems odd question, i'm start learning requirejs , advanced javascript.
both these modules work, question is: what's difference , why should prefer first/second way?
class="lang-js prettyprint-override">// first way define(['handlebars', 'backbone.marionette'], function() { console.log(handlebars, backbone.marionette); // ok } ); // way define(['handlebars', 'backbone.marionette'], function(handlebars, backbonemarionette) { console.log(handlebars, backbonemarionette); // ok } );
define(['handlebars', 'backbone.marionette'], function() { console.log(handlebars, backbone.marionette); // ok } );
the reason 1 works have handlebars , marionette existing in window namespace already. handlebars, backbone.marionette global values exist outside function definition. i.e :
console.log(handlebars, backbone.marionette); // ok define(['handlebars', 'backbone.marionette'], function() { console.log(handlebars, backbone.marionette); // ok } );
requirejs
No comments:
Post a Comment