Simple implementation of JS rewrite method _javascript skill

Source: Internet
Author: User

As shown below:

Function.prototype.method = function (name, FN) {
  This.prototype[name] = Fn;//this refers to the Function.prototype object
  Return this;//returns this object, which facilitates cascading operations like JQ

};

Number.method ("Interge", function () {

});//number is a constructor, so it has the above method, so it finally returns the number object (constructor), so you can ( -10/ 3). Interge () to be

continued.

//Main is the method



of calling the parent class Obj.method ("Surper", function (name) {
    var = this;
    var method = That[name];
    return function () {return
         method.apply (that,arguments);//If there is not that, there will be no cat.getname (that is an object)
    }
  });/ /The following is an application of

var Coolcat = function (spec) {

      var that = cat (spec);/personal feeling here, where that can have cat there are "some methods"

      var GetName = That.surper ("GetName");//The feeling here should be done with the newly generated object, which should be better. It's best not to that.

      That.get_name= function () {return

            "Me" +getname () + "Me";


      }

      return that;


}

The above comes from "the JavaScript language pristine," which is really good.

The above JS rewrite method of simple implementation is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.