JS Classic Code Learning one: Using ternary operators to handle JavaScript compatibility

Source: Internet
Author: User

Window. Event ={add:function() {            //use conditional expressions to detect whether a standard method exists            returnDocument.addeventlistener?function(A, B, c) {/*use the standard method if the standard method exists. Note here that this will write false as "! 1", which is better than writing "false" directly. I think it's supposed to reduce the volume of files by writing a few characters less. Because JS is to be downloaded to the user's computer to perform, so will! 1 automatic conversion to false is not a good thing for the user's computer resource overhead, but if each false saves three characters, if there is a lot of false in a file, you can save a considerable amount of bytes, This is very meaningful for large-scale concurrent access. */A.addeventlistener (b, C,!1)            }: function(A, B, c) {a.attachevent ("On" +b, c)} } (), remove:function() {            returnDocument.removeeventlistener?function(A, B, c) {A.removeeventlistener (b, C,!1)            }: function(A, B, c) {a.detachevent ("On" +b, c)} } (), Stop:function(a) {a&& a.stoppropagation? (A.stoppropagation (), A.preventdefault ()): (window.event.cancelBubble =! 0, Window.event.returnValue =!1)        }    }; 

JS Classic Code Learning one: Using ternary operators to handle JavaScript compatibility

Related Article

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.