JavaScript High-quality code 04

Source: Internet
Author: User

Design of libraries and APIs:

    • Keep a good habit in the design of parameters: such as order, width,height;top,right,bottom,left;
    • Consider undefined as no value and not as a non-specific value;
    • In a place where 0, an empty string, and so on are valid parameters, do not pass the Truth Test (| | ) to implement the default value of the parameter;
      Use//var x = = = undefined? 0:x;
    • Optional object can be used when the multi-parameter object is accepted;
    • Extend can be used when working with multiple presets
      function extend (target, source) {if (source) {= (var key in source) {var val = source[key];if (typeof val!== ' undefined ') {Target[key] = val;}}} return target;} function Alert (parent, opts) {opts = Extend ({width:320,height:240}, opts); opts = Extend ({x: (PARENT.WIDTH/2)-(Opts.wid th), Y: (PARENT.HEIGHT/2)-(Opts.height), title: ' Alert ', icon: ' Info ', modal:false}, opts); Extend (this, opts);} var alert = new Alert ({width:1200,height:1000},{title: ' child ', modal: ' true '});
    • Use a stateless API whenever possible;

JavaScript High-quality code 04

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.