Java Programmer's JavaScript learning Note (10--jquery-extends at "class" level)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.