"jquery", "jquery technology Insider" read Note one

Source: Internet
Author: User

jQuery( object )

jquery when constructing objects, in addition to using a very useful CSS selector to find the DOM, you can also pass in a JavaScript object to generate a jquery object.

Jsvar foo = {name: "foo", Hello: "word"};var $foo = $ (foo), $foo. On ("Custom", function () {Console.log (THIS.name + "" + This.hello);}); $ (function () {$ ("#btn"). Bind (' click ', Function () {$foo. Trigger ("Custom");}); /Html<button id= "BTN" > Trigger </button>

  

为什么要在构造函数jQuery() 内部用运算符new创建并返回另一个构造函数的实例

For jquery's constructor, you can actually understand it in a different way, so I wrote the following code based on jquery code:

(function (window,undefined) {var factory = (function (obj) {var NewObj = function (obj) {return new NewObj.fn.init (obj);} Newobj.fn = newobj.prototype={constructor:newobj,init:function (obj) {this.context = {Name:obj};return This;},print: function () {console.log (this.context.name);}} NewObj.fn.init.prototype = Newobj.fn;return NewObj;}) (); window.factory = window. FC = Factory;}) (window); FC ("Hello word"). Print ();

In the source code, the factory and newobj in the above codes are actually writing jquery, so it's easier to lead to conceptual confusion. So I changed a name so that I could distinguish it.

We can clearly see that the overall architecture of jquery can actually be equivalent to a factory model. Factory generates a Newobj object in the internal new creation, based on an externally-passed object, obj.

This allows you to omit the new operator when you create a Newobj object. This makes it easier to create and invoke newobj objects.

getElementById浏览器兼容问题

IE7 below and some opera versions, when you use getElementById to get elements, you will find them by name. Good pit Daddy Ah, this also can??!!

Calling createdocumentfragment for document insertion can significantly improve performance, ( 待确认! )

"jquery", "jquery technology Insider" read Note one

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.