Plan to complete this note in the following order:
1. Philosophy.
2. Attribute copying and inheritance.
3. This/call/apply.
4. Closure/getter/setter.
5. prototype.
6. Object-oriented simulation.
7. The basic mechanism of jquery.
8. jquery Selector.
9. jquery Tool method.
Jquery-expands at the "class" level.
Jquery-is expanded at the "object" level.
jquery-extension Selector.
JQuery UI.
14. Extend the jquery UI.
This is the 10th note, and we consider how to extend the query from a "class" perspective from a practical point of view.
jquery is a compact Framework that focuses on solving the most core issues, without pursuing chatty, and all the expansion mechanisms are critical to jquery.
JavaScript is based on functions, and today we are trying to build a library of functions for our projects based on jquery, each of which implements specific functions and organizes them effectively.
Author Blog: Http://blog.csdn.net/stationxp
Author Micro-Blog: http://weibo.com/liuhailong2008
Reproduced please obtain the consent of the author
1. The target calls our function library through $. Function libraries are hierarchically organized by function. The effect is as follows:
$.util.parsedate
$.util.parsedecimal
$.page.event.init
2, the method of the previous article we learned that through the jquery.extend () can easily expand the jquery, and even to cover the extend itself.
Jquery.extend () supports the following types of function signatures:
Jquery.extend (obj);
Jquery.extend (Isdeep,obj);
Jquery.extend (Target,src1,src2,...);
Jquery.extend (Isdeep,target,src1,src2,...);
We can extend the source code on the basis of modification, and overwrite the original extend, so modify a potentially widely used function, modify other people's expectations of the input parameters, is inappropriate, may mislead others, entered the wrong parameters, bring the wrong hidden trouble.
We redefine a method, as follows:
Jquery.extend ({ns_extend:function () {var ns, NSS, Target, I, src, length; length = Arguments.length;if (length>1) {ns
= Arguments[0]; i = 1;} else {i = 0;} if (! (src = arguments[i]) | | ! Jquery.isplainobject (SRC)) {return;} target = this;if (ns) {NSS = Ns.split ('. ');//TODO here need to do a multi-character filter processing for (var idx = 0; idx < nss.length; ++idx) {ns = NSS [idx];//NS semantics changed, original semantic mission ended, here as temporary variable ns = Jquery.trim (ns); if (NS) {Target[ns] = Target[ns] | | {};target = Target[ns];}}} for (; i < length; ++i) {src = arguments[i];jquery.extend (target, SRC);}}); Jquery.ns_extend (' pet ', {miao:function () {alert (' I am a cat ');}}); Jquery.ns_extend (' My.fav.pet ', {wangwang:function () {alert (' I am a dog ');}}); $.pet.miao (); $.my.fav.pet.wangwang ();
Aim to achieve!
Java Programmer's JavaScript learning Note (10--jquery-extends at "class" level)