javascript - Module naming in RequireJS -
We can use AMD compatible versions of backbones and underscore JS
AMD compatible libraries
Backbone JS (AMD);
else if (for typeof defined === 'function' & amp; amp; both () and below is the relevant code;; & amp; def; define.amd) {// AMD define In this case, this script is loaded in case of (['underscores', 'jquery', 'export'], function (_, $, export) {// Export AMD case // Other, which is still a global backbone Can expect the bone. Root.Backbone = factory (root, export, _, $);});
Underscore JS (AMD);
// AMD defines the AMD loader at the end of compatibility with / / which does not apply to the next-tern semantics if the module is defined (typef === 'function' & amp; ; Define. AMD) {Define ('underscore', function () {return _;}); }
Now in our code to use these AMD compatible libraries, we say; Needjs.config ({enforceDefine: true, path: {"jquery": "Libs / jquery-1.8.3", "underscore": "Libs / underscore-AMD", "backbone ":" Libs / Backbone-AMD "}});
I have now read that the name of the backbone module can be anything, but the underscore should be "underscores" and it should be underscores, capitalization is important.
I do not understand why the difference is based on how the library is defined
Can you please explain it to me.
to define the module with or without the name defined
function Can be called. This module does not have the name of the module, it starts with an array of dependencies:
define (['underscores', 'jquery', 'export'], function (_, $, Export) { will specify a module name based on the base name of the RequireJS file that appears in defined
or by the name that you < Code> path
configuration. You can enter the path: {platypus: '... path to file'}
and your module will be named plateus
. This is the name of the module of the call:
define ('underscore', function) { > Underscore
. (The first argument is not an array, therefore RequireJS interprets it as a module name.) And when the name is set with defined
, it never changes. So when you call it a dependency it is called underscore
. (You can change the name in your requisitionJS config but ultimately the module name is set to underscore
.) If you tried the plateit
example above with this module , RequJS will cause an error because it will get a module named underscore
but there is no platypus
name due to doing so clear Modify module name in and enough without defined
calls T to Bad Behavior . This document is not required for the RequireJS:
This [i.e. Module name] Generally generated by the optimization tool you can explicitly give yourself a module name, but it makes the module less portable - if you move the file to another directory then you have to change the name . Usually, to avoid coding by the name of the module is best and burn the optimization tool in module names. The optimization tool needs to add a name so that more than one module can be bundled in a file to allow faster loading in the browser.
Comments
Post a Comment