"JavaScript" JavaScript simulation class

Source: Internet
Author: User

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

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.