1. When writing widgets, we usually need to bind some events. It is best to add the binding events of these widgets to the namespace of the current widget. If two widgets are used for the same jquery object, and both widgets are bound with the same event name, the problem may occur. It is also convenient to remove binding events when destroying Widgets. You only need unbind (". namespace.
2. When writing jquery, because jquery objects support continuous writing. For example, watermark (obj).css ("height", "20px"). ATTR ("title", "ABC ")....
3. You can use the native method of JavaScript to avoid switch during writing.
CopyCode The Code is as follows: Switch ()
{
Case "AA ":
This. _ set_aa ();
Break;
Case "BB ":
This. _ set_bb ();
Break;
Case "cc"
This. _ set_cc ();
Break;
}
The above code can be replaced with the following codeCopy codeThe Code is as follows: This ["_ SET _" + A] ();
4. cache jquery objects and various variables as much as possible. This improves the script performance.
5. cache the this pointer using variables. This can be minimized when code is minimized.
6. It is best to take the CSS class name with the same name and save the definition variable. When using the variable directly, even if the CSS name is adjusted, you only need to change the value of the variable cache. At the same time, the Code can also reduce the size when minimized.
7. During setoption, if an option is a complex object instead of a simple value object, it is best not to simply this. options [Key] = value. before that, you need to make an extend between the value and the previous option value, and then assign a value to keep the original part of the complex object. For example:Copy codeThe Code is 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}, and the height: 200 will be lost. The following one will keep the original height: 200.