Read some of the nine flaws in jquery _jquery

Source: Internet
Author: User
1,bind method, the last parameter FN is redundant
Copy Code code as follows:

Handle Object Literals
if (typeof type = = = "Object") {
for (var key in type) {
this[name] (key, data, Type[key], FN);
}
return this;
}

2, note
Copy Code code as follows:

Add which for click:1 = = left; 2 = = middle; 3 = = Right

should be amended to read
Copy Code code as follows:

Add which for mousedown/mouseup:1 = = left; 2 = = middle; 3 = = Right

3,data method, the local variable internalkey is defined, but the following code still follows Jquery.expando.
Copy Code code as follows:

var internalkey = Jquery.expando, getbyname = typeof name = = = "String", Thiscache,

4,jquery.event.add method, arguments changed to e,apply instead of call better. Because only one argument is passed: the event object.
Copy Code code as follows:

Elemdata.handle = Eventhandle = function (e) {
Discard the second event of a JQuery.event.trigger () and
When the event is called after a page has unloaded
Return typeof jQuery!== "undefined" && (!e | | jQuery.event.triggered!==)?
JQuery.event.handle.apply (Eventhandle.elem, arguments):
Undefined

};

5, based on the "Do not repeat detection browser" principle, jQuery.event.add the following code
Copy Code code as follows:

if (Elem.addeventlistener) {
Elem.addeventlistener (Type, eventhandle, false);

else if (elem.attachevent) {
Elem.attachevent ("On" + Type, eventhandle);
}

You should use the following to replace
Copy Code code as follows:

Jquery.addevent = Document.addeventlistener?
function (elem, type, handle) {
if (Elem.addeventlistener) {
Elem.addeventlistener (type, handle, false);
}
} :
function (elem, type, handle) {
if (elem.attactevent) {
Elem.attactevent ("On" + type, handle);
}
};

In fact, jquery has a jquery.removeevent, but somehow there is no jquery.addevent.

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.