jQuery2.1.1 Source Code Analysis (i)---mini-jquery framework

Source: Internet
Author: User

Many mistakes, lots of advice.

Remove the cumbersome code, which is equivalent to a miniature jquery framework.

A JS function, the closure of the input window variable run,
(function(window) {
Defines a jquery assignment to 3 variables, returning an instantiation of an object JQuery.fn.initvarJQuery = Window.jquery = window.$ =function(Selector, context) {return NewJQuery.fn.init (selector, context); };
Defines the Fn,jquery.prototype under JQuery as an object Jquery.fn= Jquery.prototype = {
function named Init, the function is to warn the first parameter selector init:function(Selector, context) {alert ("The currently selected element is:" +selector); },
Add function, warning text, return this, point to, convenient chain call, add:function() {alert ("Execution method: Add ()"); return This; } }
For chained calls, the entire jquery function function is within each init function. JQuery.fn.init.prototype=Jquery.fn;}) (window); $("DD"). Add (). Add (); The element that pops up the current selection is: DD,

——————————————————————
Knowledge Points:
1. Closures
Http://www.cnblogs.com/dewin/archive/2010/06/17/1759477.html

2. function can be called with $
The original code var jQuery = window.$ = Window.jquery;
When you visit outside the closure, such as with JQuery, the window.jquery,$ is actually the same as the global variable. The global member in JS refers to adding properties to the window, and vice versa.

3.

$ ("DD"). Add (). Add ();
In a logical order, $ ("DD") accesses the function and passes the first parameter DD, returning a pending block.
Instantiate, New JQuery.fn.init (), locate the function declaration, jquery.fn the property of the object of the Init function. Pass in the parameter dd, execute function, will pop up the currently selected element is: DD;
$ ("DD"). Add (), pass

()

jQuery2.1.1 Source Code Analysis (i)---mini-jquery framework

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.