The generic JavaScript framework is implemented by injecting its own properties into the Global object window. For example, jquery adds a "$" object to the window, and underscore adds an "_" object to the Window object. What if these global variables already exist before the framework is loaded?
<script>var $ = "$"; </script><script src= "Jquery-1.10.2.js" ></script><script>alert ($ = = = "$");//falsealert ($ (). jquery);//1.10.2</script>
Obviously $ is occupied by the jquery framework, and the value of the $ variable that we defined previously is overwritten. If you want to use the jquery framework, you want to use the $ variables you defined earlier. Then the Noconflict () function comes in handy.
<script>var $ = "$"; </script><script src= "Jquery-1.10.2.js" ></script><script>var Stilljquery = $.noconflict (); alert (Stilljquery (). jquery);//1.10.2alert ($ = = = "$");//true</script>
The general JavaScript Framework is the following structure, the implementation principle is as follows:
(function (window) {///save data var _$e = window. $E; var myplugin = {"Name": "aty"};myplugin.noconflict = function () {window. $E = _$e;return myplugin;};/ /register $ewindow with the Global object. $E = Myplugin;}) (window);
The use and implementation principles of Noconflict () in JavaScript frameworks such as Jquery/underscore