forked from tjbutz/class.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.min.js
executable file
·2 lines (2 loc) · 5.77 KB
/
class.min.js
1
2
/*! class.js v0.6 https://github.com/tjbutz/class.js | License: https://github.com/tjbutz/class.js/blob/master/LICENSE */
(function(){"use strict";var a=this,b=a._;!b&&typeof require!="undefined"&&(a._=b=require("underscore"));var c=a.Class,d;typeof exports!="undefined"?d=exports:d=a.Class={},d.VERSION="0.5.2",d.root=a,d.noConflict=function(){return a.Class=c,this};var e=function(){};b.extend(d,{definition:[],define:function(a,c){b.isFunction(a)||(c=a,a=null),d.onBeforeClassDefine&&d.onBeforeClassDefine(a,c);var f=null;c&&c.hasOwnProperty("constructor")&&(f=c.constructor,delete c.constructor);var g=function(){if(this instanceof g)d.onBeforeInstantiation&&d.onBeforeInstantiation(this),f?f.apply(this,arguments):a&&a.apply(this,arguments),d.onAfterInstantiation&&d.onAfterInstantiation(this);else throw new Error("Use new keyword to create a new instance or call/apply class with right scope")};a&&(e.prototype=a.prototype,g.prototype=new e,g.constructor=g,g.prototype.__super__=a.prototype);if(c){b.each(this.definition,function(a){typeof c[a]!="undefined"&&(this[a].call(this,g,c[a]),delete c[a])},this);if(b.keys(c).length!==0)throw new Error("Unknown key in definition: "+b.keys(c).join(", ")+". Allowed keys are: "+this.definition.join(", "))}return g.extend=this._extend,d.onAfterClassDefine&&d.onAfterClassDefine(g),g},_extend:function(a){return d.define(this,a)}})}).call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.definition.push("namespace"),a.namespace=function(a,c){if(b.isString(a)){var d=c;c=a,a=d}c=c.split(".");var e=this.root;if(c.length>0){var f=c.pop();b.each(c,function(a){e=e[a]=e[a]||{}}),e[f]=a}return a}}.call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.definition.push("singleton"),a.singleton=function(a,b){b&&(a.$$instance=null,a.getInstance=function(){return this.$$instance||(this.$$instance=new this)})}}.call(this),function(){"use strict";var a=this.Class||exports,b=a.root._;a.definition.push("statics"),a.statics=function(a,c){b.extend(a,c)}}.call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.error=a.error||function(a){throw a},a.ECMA5=!1,a.types={String:b.isString,Number:b.isNumber,Boolean:b.isBoolean,Array:b.isArray,Function:b.isFunction,Object:b.isObject,Element:b.isElement,Regex:b.isRegExp},a.definition.push("properties"),a.properties=function(a,b){for(var e in b)d(a,e,b[e]);var f=a.prototype;f.set=c("set"),f._set=c("_set")};var c=function(a){return function(c,d){if(b.isString(c)){var e=c;c={},c[e]=d}for(var e in c){var f=l(e),g=a+f;if(this[g])this[g](c[e]);else throw new Error('No public set method for property "'+e+'" found.')}return this}},d=function(c,d,i){b.isObject(i)||(i={type:i});var j=c.prototype,k=e(d,i,"set"),l=e(d,i,"get");a.ECMA5?(j.__defineSetter__(d,g(d,i,l,k)),j.__defineGetter__(d,f(d,i,l,k))):(j[k]=g(d,i,l,k),j[l]=f(d,i,l,k));if(i.type==="Boolean"){var m=e(d,i,"is");j[m]=h(d,i,l,k)}},e=function(a,b,c){var d=l(a),e=c+d;return b[c==="is"?"get":c]===!1&&(e="_"+e),e},f=function(b,c,d,e){return function(){this.$$properties=this.$$properties||{};if(typeof c.init!="undefined"){var d=c.init;delete c.init,a.ECMA5?this[b]=d:this[e](d)}return this.$$properties[b]}},g=function(c,d,e,f){return function(f){var g;a.ECMA5?g=this[c]:g=this[e]();if(d.format){var h=b.isString(d.format)?this[d.format]:d.format;if(h)f=h.call(this,f,g,c);else throw new Error('Format method "'+d.format+'" for property "'+c+'" not available.')}var i=d.type,j=b.isNull(f)&&d.nullable===!0;if(!j&&i){var l=b.isFunction(i)?k:a.types[i];if(!l)throw new Error('Unknown type "'+i+'" for property "'+c+'".');if(!l.call(this,f)){var m='Wrong type for property "'+c+'". Expected value "'+f+'" to be of type "'+i+'" but found: '+typeof f;m+=". Allowed keys are: "+b.keys(a.types).join(", "),a.error(new a.TypeError(m,c,f,i));return}}var n=d.validate;n&&(b.isArray(n)||(n=[n]),b.each(n,function(e){e=b.isString(e)?this[e]:e;if(!e)throw new Error('Validation method "'+d.validate+'" for property "'+c+'" not available.');var h=e.call(this,f,g,c),i=b.isString(h);if(!h||i){var j=i?h:'Validation for property "'+c+'" with value "'+f+'" failed';a.error(new a.ValidationError(j,c,f));return}},this)),this.$$properties[c]=f;if(d.hasOwnProperty("apply")){var h=b.isString(d.apply)?this[d.apply]:d.apply;if(h)h.call(this,f,g,c);else throw new Error('Apply method "'+d.apply+'" for property "'+c+'" not available.')}if(d.event){var o=this.trigger||this.emit;if(o)o.call(this,d.event,{target:this,value:f,old:g,property:c});else throw new Error("Object does not support events")}return f}},h=function(a,b,c,d){return function(){return this[c]()}},i=a.ValidationError=a.define(Error,{constructor:function(a,b,c){this.name="ValidationError",this.message=a||"Validation Error",this.property=b,this.value=c}}),j=a.TypeError=i.extend({constructor:function(a,b,c,d){i.apply(this,arguments),this.name="TypeError",this.message=a||"Type Error",this.type=d}}),k=function(a){return this instanceof a},l=function(a){return a.charAt(0).toUpperCase()+a.substring(1)}}.call(this),function(){"use strict";var a=this.Class||exports,b=a.root._;a.definition.push("mixins"),a.mixins=function(a,c){b.each(c,function(c){var c=b.isFunction(c)?c.prototype:c;b.extend(a.prototype,c)})}}.call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.definition.push("members"),a.members=function(a,c){b.extend(a.prototype,c)}}.call(this),function(){"use strict";var a=this.Class||exports,b=this._;a.definition.push("interfaces"),a.interfaces=function(a,d){b.each(d,function(d){var d=b.isFunction(d)?d.prototype:d;for(var e in d){var f=a.prototype[e];if(typeof f=="undefined"||!b.isFunction(f))throw new Error('The Class does not implement the interface method "'+f+'"');b.isFunction(d[e])&&(a.prototype[e]=c(d[e],f))}})};var c=function(a,b){return function(){return a.apply(this,arguments),b.apply(this,arguments)}}}.call(this);