Introduce The Cmd(Common Module Definition)To Yii2

now the jquery is a buildin js lib for yii . i don’t know the next version of yii which lib will use(mostly the jquery :lol: ) ? even if the jquery is the mostly used js lib for web developers but there are still some developers use other js lib eg: mootools ,dojo ,extjs …

if you see the source code of jquery new version ,you will find some intresting code piece :

// Expose jQuery as an AMD module, but only for AMD loaders that

// understand the issues with loading multiple versions of jQuery

// in a page that all might call define(). The loader will indicate

// they have special allowances for multiple jQuery versions by

// specifying define.amd.jQuery = true. Register as a named module,

// since jQuery can be concatenated with other files that may use define,

// but not use a proper concatenation script that understands anonymous

// AMD modules. A named AMD is safest and most robust way to register.

// Lowercase jquery is used because AMD module names are derived from

// file names, and jQuery is normally delivered in a lowercase file name.

// Do this after creating the global so that if an AMD module wants to call

// noConflict to hide this version of jQuery, it will work.

if ( typeof define === "function" && define.amd && define.amd.jQuery ) {

	define( "jquery", [], function () { return jQuery; } );


above is from jquery 's source code version1.9 . in fact the jquery have supportted the AMD spec of CommonJSAsynchronousDefinition(AMD) and you can use like this (module SPEC) , thus jquery can be used as a “module” , and some other mainstream js lib also support this feature (you can google it ).

so we can use different js lib as a module of our web front end .and no conflict . if we introduce such a method to yii2 we can switch to any js lib if we want , and the AMD methodology will bring us a huge benefit . we can reuse our old js functionality as a reusable module just like yii’s CModule in front end in diffent project .we can publish our js functionality as a “module” wich is a self contained just like a anonymous function(there is no naming conflict) and combine the webservice (you can publish methods ,properties to outdoor ).

some one may have heard the requreJS and yepnope.jsyepnopeJs ,such js lib will change our js develop way ,and make life easy . so what’s your opinion :D