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