Java programmer's JavaScript Study Notes (10 -- jQuery-extensions at the class level)

Source: Internet
Author: User

Java programmer's JavaScript Study Notes (10 -- jQuery-extensions at the class level)
We plan to complete this note in the following order:
1. concept.
2. Copy and inherit attributes.
3. this/call/apply.
4. Closure/getter/setter.
5. prototype.
6. object-oriented simulation.
7. Basic jQuery mechanism.
8. jQuery selector.
9. jQuery tool method.
10. jQuery-extension at the class level.
11. jQuery-extensions at the "object" level.
12. jQuery-extended selector.
13. jQuery UI.
14. Extend the jQuery UI.
This is Part 1 of the notes. We will consider how to expand the home Query from a practical perspective from the perspective of "class.

JQuery is a compact framework that focuses on solving the core issues without the pursuit of big and complete. All extension mechanisms are crucial to jQuery.
JavaScript is based on functions. Today, we try to build a function library for our own projects based on jQuery. Each function implements specific functions and effectively organizes these functions.

 

1. The target calls our function library through $. Function libraries are organized by function. The effect is as follows:
$. Util. parseDate
$. Util. parseDecimal
$. Page. event. init

2. As we learned in the previous article about the method, jQuery. extend () can be used to easily expand jQuery, and even overwrite extend itself.
JQuery. extend () supports the following function signatures:
JQuery. extend (obj );
JQuery. extend (isDeep, obj );
JQuery. extend (target, src1, src2 ,...);
JQuery. extend (isDeep, target, src1, src2 ,...);
We can modify the source code of extend and overwrite the original extend. This modifies a function that may be widely used and modifies others' expectations for input parameters, other people may be misled, and incorrect parameters may cause errors.

Let's 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 multi-character filtering is required here for (var idx = 0; idx <nss. length; ++ idx) {ns = nss [idx]; // The meaning of ns has changed. The original semantic mission ends. This is used as a temporary variable ns = jQuery. trim (ns); if (ns) {target [ns] = target [ns] | |{}; target = target [ns] ;}} (; 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 ();

Goal fulfillment!

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.