Beauty ("$Class", ["$underscore"],function (_) {var Class = function () {var length = Arguments.length; var option = arguments[length-1]; Option.init = Option.init | | function () {}; If the parameter has a parent class to inherit if (length = = = 2) {/** * @ignore */var superclass = Arguments[0].extend; /** * @ignore * */var tempclass = function () {}; Tempclass.prototype = Superclass.prototype; /** * @ignore */var subclass = function () {this.init.apply (this, Argu ments); }; Plus a static property reference to the parent class prototype Subclass.superclass = Superclass.prototype; Subclass.superclass = superclass; /** * @ignore */subclass.callsuper = function (context, func) {var sli CE = Array.prototype.slice; var a = SLIce.call (arguments, 2); var func = Subclass.superclass[func]; var func = Subclass.superclass.prototype[func]; if (func) {func.apply (context, A.concat (Slice.call (arguments))); } }; Specify prototype Subclass.prototype = new Tempclass (); Reassign constructor subClass.prototype.constructor = subclass; _.extend (subclass.prototype, option); /** * @ignore */subClass.prototype.init = function () {//Call the constructor of the parent class SubClass.superClass.init.apply (this, arguments); Call the constructor of this class itself option.init.apply (this, arguments); }; return subclass; If there is no parent class in the argument, simply construct a class} else {if (length = = 1) {/** * @ignore */var Newclass = function () {//AddedReturn, otherwise the object returned by Init does not take effect return this.init.apply (this, arguments); }; newclass.prototype = option; return newclass; } } }; Beauty. $superPackage ("$Class", Class);});
"JavaScript" JavaScript simulation class