When expanding JavaScript, be sure to keep all of its original features

Source: Internet
Author: User

When expanding JavaScript, be sure to keep all of its original features, because you don't know if someone else's code is going to use them. And generally speaking, in order to write compatible with more JS framework code, the most insurance method is to use JS native function. However......

On this issue, this asp.net AJAX rc cropper.

I wonder if you have seen the ASP.net AJAX Library rc for JavaScript extensions? This adds some code to the extension of the RC:

Date._jsParse = Date.parse;
...
Date.parse = function Date$parse(value, formats) {
  ...
}

The code above changes the native implementation of Date.parse to the Date._jsparse function, redefining a Date.parse method. In doing so, it is a good extension to provide a more unified parse feature for number, Date, and Boolean objects, and to support various format and localization capabilities. Unfortunately, because of the original function of JavaScript, Google Ads has been widely used ... Thing, that's the break.

This problem is directly related to the immediate interests of the general public, seriously affecting the feelings of the masses. For example, in the ASP.net Ajax forum, is complaining about this matter (http://forums.asp.net/thread/1499508.aspx), but some of the problems naturally will be solved, such as Cyril (see this face is familiar, originally my " Another method of Atlas Scripts IntelliSense, as well as a comparison and analysis, refers to his blog's approach and proposes a solution:

Date.__cyril_parse = Date.parse;
Date.parse = function(s){
  try {
    return Date.__cyril_parse(s);
  } catch (e){
    var d = Date._jsParse(s);
    if (d) {
      return d;
    } else {
      throw e;
    }
  }
}

Just introduce the code above. This is easy to think of, but there is really no simpler or more effective solution: Put the asp.net ajax date.parse extension to another save, and then write a Date.parse method, first try to asp.net the extension of Ajax, If it fails (fortunately if the user fails in the way it used to be), invoke the original functionality of JavaScript. That's how the problem is solved, isn't it?

This asp.net AJAX rc error is very low-level, but only RC, there are problems are not afraid. However, this is not the purpose of RC release? At least now it is almost certain that the extensions in the ASP.net Ajax official version will not have this error again.

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.