Jxunderscore (Function (J, _, root) {var iswindow, deepobject, Namespace, Class, LOG; /** * Whether an object is a Window object * @param obj * @returns {boolean} */IsWindow = function (obj) {return!! obj && Obj.window = = = window; }; /** * Method for printing logs */log = (function () {if (IsWindow (root)) {if (!! Window.console) {return {error:function (s) {WINDOW.CONSOLE.L OG ("[ERROR]" + s); }, Debug:function () {Window.console.log ("[Debug]" + s); } }; } else {return {error:function (s) {Window.alert (s) }, Debug:function () {}}}} else { return {error:function () { }, Debug:function () {}}; } })(); /** * Create/Get a namespace/package * @param NamespacePath * @param context * @returns {*} */deepobject = function (NamespacePath, context) {if ("string"!== typeof NamespacePath) {return undefined; } var ns = Context | | Root var Patharr = Namespacepath.split ('. '); for (var i = 0; i < patharr.length; i++) {var path = patharr[i]; Ns[path] = Ns[path] | | {}; NS = Ns[path]; } return NS; }; /** * Class class * @class * @memberOf Jx * @param {Object} option = {Extend:superclass} in Opti The object that is to be inherited is specified in the Extend property of the on object, and you can not write an object that has an extension of * @param {object} * @return {object} class * * @example * * var person = new J.class ({* Init:function (name) {* THIS.name = name; * Alert ("init"); * }, * Showname:function () {* alert (this.name); * *} * * * * *//Inherit person * var Person2 = new J.class ({Extend:person}, {* in It:function (name) {* THIS.name = name; * Alert ("init"); *}, * Showname:function () {* alert (this.name); * * } * * }); * * }; * */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, arguments); }; 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 () {//Added return, otherwise the object returned by Init does not take effect return this.init.apply (this, arguments) ; }; newclass.prototype = option; return newclass; } }; /** * Create/Get a namespace/package * @param {String} NamespacePath * @param {function} workspace * @constructor * @e Xample * J.namespace ("jx.ui.pm", function (PM) {* Return {* A: "A", * B: "B" * } * }); * J.package ("jx.ui.pm", function (PM) {* var a=pm.a; * Return {* c: "C" +a, * d: "D" *}; * }); */Namespace = function (NamespacePath, workspace) {NamespacEpath = NamespacePath | | ""; Workspace = Workspace | | function () {}; var namespaceobj = Deepobject (NamespacePath); if (namespaceobj) {var result = workspace (namespaceobj); if (_.isobject (Result)) {_.extend (namespaceobj, result); } else {Log.error ("The return value is a object,namespace:" + NamespacePath); } } }; J.namespace = Namespace; J.package = Namespace; J.class = Class; J.iswindow = IsWindow; J.createdeepobject = Deepobject; J.LOG = LOG; return {namespace:namespace, package:namespace, Class:class, Iswindow:iswindow, CR Eatedeepobject:deepobject, Log:log};});
"JavaScript" creates a namespace, Class,log