As shown below:
Function.prototype.method = function(name, fn) { this.prototype[name] = fn;//this should refer to the Function.prototype object return this;//Return this object, this helps with cascade operations like jq}; Number.method("interge",function(){});//Number is a constructor, so it has the above method method, so the Number object (constructor) is returned in the end, so it can (-10/3).interge() to be continued. . //The main thing is to call the parent class method Obj.method("surper",function(name){ var that = this; var method = that[name]; return function(){ return method.apply(that,arguments);//If there is no that here, there will be no cat.getName(that(is an object)) } });//The following is an application var coolcat = function(spec){ var that = cat(spec);//I personally feel that here, there can have "some methods" var getName = that.surper("getName");//This feels that it should be done with the newly generated object, which should be better. It is better not to use that. that.get_name= function(){ return "me"+getName()+"me"; } return that;}The above content comes from "Javascript Language Essence", which is really good.
The simple implementation of the above js rewriting method is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.