nonatque
Version:
A javascript OOP toolkit for mobile.
1 lines • 5.98 kB
JavaScript
!function(){var a,i,s,n,e,_,o,r,c,f,t="object"==typeof global&&global&&global.Object===Object&&global,u="object"==typeof self&&self&&self.Object===Object&&self,t=t||u||Function("return this")(),u="object"==typeof exports&&exports&&!exports.nodeType&&exports,p=u&&"object"==typeof module&&module&&!module.nodeType&&module,h=t.nx=t.nx||{BREAKER:{},VERSION:"1.1.4",DEBUG:!1,GLOBAL:t};function l(t){return t.replace(e,".$1").replace(_,a).replace(o,"")}function d(){}function y(t,e){this.type=t,this.meta=e,this.base=e.extends||h.RootClass,this.$base=this.base.prototype,this.__class_meta__={},this.__class__=null,this.__constructor__=null}"function"==typeof define&&"object"==typeof define.amd&&define.amd?(t.nx=h,define(function(){return h})):p?((p.exports=h).nx=h,u.nx=h):t.nx=h,a=".",i="undefined",s=Array.prototype,n=Object.prototype.hasOwnProperty,e=/\[(\w+)\]/g,_=/[.]+/g,o=/^\.|\.$/g,h.noop=function(){},h.stubTrue=function(){return!0},h.stubFalse=function(){return!1},h.stubValue=function(t){return t},h.error=function(t){throw new Error(t)},h.try=function(t){try{t()}catch(t){}},h.forEach=function(t,e,_){for(var s=t.length,i=0;i<s&&e.call(_,t[i],i,t)!==h.BREAKER;i++);},h.forIn=function(t,e,_){for(var s in t)if(n.call(t,s)&&e.call(_,s,t[s],t)===h.BREAKER)break},h.each=function(s,i,o){function t(t,e,_){return i.call(o,t,e,s,_)===h.BREAKER}var e,_;if(s)if("number"==typeof(_=s.length))for(e=0;e<_&&!t(e,s[e],!0);e++);else for(e in s)if(n.call(s,e)&&t(e,s[e],!1))break},h.map=function(t,e,_){var s=[];return h.each(t,function(){var t=e.apply(_,arguments);if(t===h.BREAKER)return h.BREAKER;s.push(t)}),s},h.mix=function(t){for(var _=t||{},e=arguments,s=1,i=e.length;s<i;s++)h.forIn(e[s],function(t,e){_[t]=e});return _},h.slice=function(t,e,_){return s.slice.call(t,e,_)},h.set=function(t,e,_){for(var s=l(e).split(a),i=t||h.GLOBAL,o=s.length-1,e=s[o],n=0;n<o;n++)var r=s[n],c=isNaN(+s[n+1])?{}:[],i=i[r]=i[r]||c;return i[e]=_,t},h.get=function(t,e,_){var s;return e?(e=l(e).split(a),s=t||h.GLOBAL,e.forEach(function(t){s=s&&s[t]}),typeof _!=i&&typeof s==i?_:s):t},h.del=function(t,e){for(var _=l(e).split(a),s=0;s<_.length;s++){var i=_[s];if(s===_.length-1)return delete t[i],!0;t=t[i]}return!1},h.path=function(t,e,_){return null==_?this.get(t,e):this.set(t,e,_)},p={__class_id__:0,__type__:"nx.RootClass",__base__:Object,__meta__:{},__static__:!1,__statics__:{},__properties__:{},__methods__:{},__method_init__:h.noop,__static_init__:h.noop},u={base:function(){var t=this.base.caller;if(t&&(t=t.__base__))return t.apply(this,arguments)},parent:function(t){var e=void 0===this.__id__,_=h.slice(arguments,1),s=e?this.__base__:this.__base__.prototype,e=this["@"+t].__type__,i=["get","set"][_.length];switch(e){case"method":return s[t].apply(this,_);case"property":return s["@"+t][i].apply(this,_)}}},p.__methods__=d.prototype=h.mix({constructor:d,init:h.noop,destroy:h.noop,toString:function(){return"[Class@"+this.__type__+"]"}},u),h.mix(p.__statics__,u),h.mix(d,p),h.mix(d,p.__statics__),h.RootClass=d,h.defineProperty=function(t,e,_,s){var i,o,n,r="@"+e,c=_&&"object"==typeof _?_:{value:_},c="value"in c?(o=c.value,n="_"+e,i=function(){return n in this?this[n]:"function"==typeof o?o.call(this):o},function(t){this[n]=t}):(i=_.get||t[r]&&t[r].get||h.noop,_.set||t[r]&&t[r].set||h.noop);return r in t&&(i.__base__=t[r].get,c.__base__=t[r].set),r=t[r]={__meta__:_,__name__:e,__type__:"property",__static__:!!s,get:i,set:c,configurable:!0},Object.defineProperty(t,e,r),r},h.defineMethod=function(t,e,_,s){var i="@"+e;return t[e]=_,t[i]={__meta__:_,__name__:e,__type__:"method",__static__:!!s}},h.defineBombMethod=function(_,t,s,i){t.split(",").forEach(function(t,e){h.defineMethod(_,t,s.call(_,t,e),i)})},h.defineMembers=function(_,s,t,i){h.forIn(t,function(t,e){-1<t.indexOf(",")?h.defineBombMethod(s,t,e,i):h["define"+_](s,t,e,i)})},r=1,c=0,f="nx.Anonymous",y.prototype={constructor:y,initMetaProcessor:function(){var t=this.meta,e=t.methods||{},_=t.statics||{};h.mix(this.__class_meta__,{__type__:this.type,__meta__:t,__base__:this.base,__class_id__:r++,__method_init__:e.init||this.base.__method_init__,__static_init__:_.init||this.base.__static_init__,__static__:!t.methods&&!!t.statics})},createClassProcessor:function(){var t=this;this.__class__=function(){this.__id__=c++,t.__constructor__.apply(this,arguments),t.registerDebug(this)}},inheritProcessor:function(){var t=this.__class_meta__;this.inheritedClass(t),this.defineMethods(t,!0),this.defineMethods(t,!1),this.defineProperties(t)},inheritedClass:function(t){function e(){}var _=this.__class__;e.prototype=this.$base,_.prototype=new e,_.prototype.$base=this.$base,_.prototype.constructor=_},defineMethods:function(t,e){var _=e?"statics":"methods",s="__"+_+"__",i=e?this.__class__:this.__class__.prototype,o=(e?this.base:this.base.prototype)[s]||{};h.forIn(this.meta[_],function(t,e){o[t]&&"function"==typeof e&&(e.__base__=o[t])}),i[s]=h.mix(t[s],o,this.meta[_]),h.defineMembers("Method",i,i[s],e)},defineProperties:function(t){var e=t.__static__,_=e?this.__class__:this.__class__.prototype,s=e?this.base:this.base.prototype;_.__properties__=h.mix(null,s.__properties__,t.__properties__,this.meta.properties),h.defineMembers("Property",_,_.__properties__,e)},methodsConstructorProcessor:function(){var t=this.__class_meta__;this.__constructor__=function(){t.__method_init__.apply(this,arguments)}},staticsConstructorProcessor:function(){this.__class_meta__.__static_init__.call(this.__class__)},registerProcessor:function(){var t=this.__class__,e=this.type,_=this.__class_meta__;h.mix(t.prototype,_),h.mix(t,_),-1===e.indexOf(f)&&h.set(h.GLOBAL,e,t)},registerDebug:function(t){h.DEBUG&&(h.set(h,"__instances__."+(c-1),t),h.set(h,"__instances__.length",c))}},h.declare=function(t,e){e=new y("string"==typeof t?t:f+r,e||t);return e.initMetaProcessor(),e.createClassProcessor(),e.inheritProcessor(),e.methodsConstructorProcessor(),e.staticsConstructorProcessor(),e.registerProcessor(),e.__class__}}.call(this);