Here is a bit exaggerated, a little hanging, just casually say that they write a graceful way to JS.
Using jquery to develop, now very popular, greatly increased speed, but also can improve the quality of the code.
1, $.extend ()
// ... -- indicates code function demo (opts) {var defualtopts={...}; OPTs=$.extend ({},opts,defaults); ... } /* use good $.extend () can be very good to pass parameters, look good beautiful */
2, {...}
/* {...} Using objects, this kind of object writing, code reusability is not strong can be used, because no need not to inherit, but also can be very intuitive. */ var demo={ init:function() { this. Action (); ... }, action:function() {...}, render:function() { ...}, delegateevent:function() {...} };
3, o.prototype={}
/* The object-oriented approach is very reusable and object-oriented is very principled, so the code looks good to understand */ function Demo () { this. v= "..."; This . Init (); } Demo.prototype={ Constructor:demo, init:function() {...}, ... }
4, the writing of jquery plugin
/*closures-Preventing global pollution*/ (function($,w,undefined) {/*Prevent multiple loads*/ if(!$.fn.demo) { /*extended jquery, can be $ (..). Demo () to execute*/$.fn.demo=(function(FN) {returnfn (); })(function(){ functionDemo () {Console.log (1); } returndemo; }); }}) (jquery,window,undefined);
Now is understood, as to what design pattern, this currently only know its type does not understand its specific use, this is the experience mode, need a lot of experience is experienced.
On the graceful writing of JavaScript