1. When writing widgets, we usually need to bind some events, preferably the binding events of these widgets plus the namespace of the current widget. If the same jquery object uses two widgets, and two widgets are bound to the same event name, there may be a problem. When destroying widgets, it is also convenient to remove the binding event, just Unbind (". Namespace") is all you need.
2, when writing jquery, because the jquery object is to support ligatures. For example: $ (obj). css ("height", "20px"). attr ("title", "ABC") ....
3. When writing, you can use JavaScript's native method to avoid switch.
Copy Code code as follows:
Switch (a)
{
Case "AA":
This._set_aa ();
Break
Case "BB":
THIS._SET_BB ();
Break
Case "CC"
THIS._SET_CC ();
Break
}
The code above can be replaced with the following code
Copy Code code as follows:
4, as far as possible to cache jquery objects, and various variables. This will improve the performance of the script
5, the use of variable caching this pointer, in the minimization of code when this can be minimized.
6, it is best to take the CSS class name consistent name, and then define the variable to save. In the use of the direct variable, so even if the CSS name adjustment, only need to change the value of the variable cache. At the same time, the code can reduce the volume when it is minimized.
7, when setoption, if an option is a complex object, rather than a simple value object, it is best not to simply this.options[key]= Value. And before that, you need to make a extend of value and previous option values, and then assign values so that you can keep a partial value of the original complex object. Like what:
Copy Code code as follows:
var a = {width:120,height:200};
var c={width:200};
A=c;
A=$.extend (A,C);
The result is that the first a will be {width:20}, the height:200 will be lost, and the one below will continue to retain the original height:200.