@jswork/next
Version:
A javascript OOP toolkit for mobile & modern web.
1 lines • 6.89 kB
JavaScript
!function(){var a,i,_,o,e,r,n,s,c,u,f,l,t="object"==typeof global&&global&&global.Object===Object&&global,p="object"==typeof self&&self&&self.Object===Object&&self,t=t||p||Function("return this")(),p="object"==typeof exports&&exports&&!exports.nodeType&&exports,h=p&&"object"==typeof module&&module&&!module.nodeType&&module,d=t.nx=t.nx||{BREAKER:{},NIL:{},VERSION:"1.2.12",DEBUG:!1,GLOBAL:t};function y(t){return t.toString().replace(n,".$1").replace(s,a).replace(c,"")}function b(){}function m(t,e){this.type=t,this.meta=e,this.base=e.extends||d.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=d,define(function(){return d})):h?((h.exports=d).nx=d,p.nx=d):t.nx=d,a=".",i="number",_="undefined",o=Array.prototype,e=Object.prototype.toString,r=Object.prototype.hasOwnProperty,n=/\[(\w+)\]/g,s=/[.]+/g,c=/^\.|\.$/g,d.noop=function(){},d.typeof=function(t){return null==t||"object"!=typeof t?null===t?"null":void 0===t?"undefined":typeof t:e.call(t).slice(8,-1).toLowerCase()},d.stubTrue=function(){return!0},d.stubFalse=function(){return!1},d.stubValue=function(t){return t},d.stubPromise=function(t){return void 0===t?Promise.resolve():Promise.resolve(t)},d.isBoolean=function(t){return"boolean"==typeof t},d.isString=function(t){return"string"==typeof t},d.isNumber=function(t){return typeof t==i&&!isNaN(t)},d.isNaN=function(t){return isNaN(t)},d.isFunction=function(t){return"function"==typeof t},d.isNil=function(t){return null==t},d.isArray=function(t){return Array.isArray(t)},d.isObject=function(t){return!Array.isArray(t)&&"object"==typeof t&&null!==t},d.isThenable=function(t){return!!t&&"object"==typeof t&&"function"==typeof t.then},d.error=function(t){throw new Error(t)},d.try=function(t,e){e=e||d.noop;try{t()}catch(t){e(t)}},d.forEach=function(t,e,n){for(var o=t.length,_=0;_<o&&e.call(n,t[_],_,t)!==d.BREAKER;_++);},d.forIn=function(t,e,n){for(var o in t)if(r.call(t,o)&&e.call(n,o,t[o],t)===d.BREAKER)break},d.each=function(o,_,s){function t(t,e,n){return _.call(s,t,e,o,n)===d.BREAKER}var e,n;if(o)if(typeof(n=o.length)==i)for(e=0;e<n&&!t(e,o[e],!0);e++);else for(e in o)if(r.call(o,e)&&t(e,o[e],!1))break},d.map=function(t,e,n){console.warn("@deprecated: nx.map is deprecated, use array.reduce instead");var o=[];return d.each(t,function(){var t=e.apply(n,arguments);if(t===d.BREAKER)return d.BREAKER;o.push(t)}),o},d.mix=function(t){for(var n=t||{},e=arguments,o=1,_=e.length;o<_;o++)d.forIn(e[o],function(t,e){n[t]=e});return n},d.slice=function(t,e,n){return o.slice.call(t,e,n)},d.set=function(t,e,n){for(var o=y(e).split(a),_=t||d.GLOBAL,s=o.length-1,e=o[s],i=0;i<s;i++)var r=o[i],c=isNaN(+o[i+1])?{}:[],_=_[r]=_[r]||c;return _[e]=n,t},d.get=function(t,e,n){var o;return e?(e=y(e).split(a),o=t||d.GLOBAL,e.forEach(function(t){o=o&&o[t]}),typeof n!=_&&typeof o==_?n:o):t},d.del=function(t,e){for(var n=y(e).split(a),o=0;o<n.length;o++){var _=n[o];if(o===n.length-1)return null!=t&&("object"==typeof t&&delete t[_],!0);t=t[_]}return!1},d.to=function(t){return t.then(function(t){return[void 0,t]}).catch(function(t){return[t,void 0]})},(h={__class_id__:0,__type__:"nx.RootClass",__base__:Object,__meta__:{},__static__:!1,__statics__:{},__properties__:{},__methods__:{},__method_init__:d.noop,__static_init__:d.noop}).__methods__=b.prototype=d.mix({constructor:b,init:d.noop,destroy:d.noop,toString:function(){return"[Class@"+this.__type__+"]"}},p={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__,n=d.slice(arguments,1),o=e?this.__base__:this.__base__.prototype,e=this["@"+t].__type__,_=["get","set"][n.length];switch(e){case"method":return o[t].apply(this,n);case"property":return o["@"+t][_].apply(this,n)}}}),d.mix(h.__statics__,p),d.mix(b,h),d.mix(b,h.__statics__),d.RootClass=b,d.defineProperty=function(t,e,n,o){var _,s,i,r="@"+e,c=n&&"object"==typeof n?n:{value:n},c="value"in c?(s=c.value,i="_"+e,_=function(){return i in this?this[i]:d.isFunction(s)?s.call(this):s},function(t){this[i]=t}):(_=n.get||t[r]&&t[r].get||d.noop,n.set||t[r]&&t[r].set||d.noop);return r in t&&(_.__base__=t[r].get,c.__base__=t[r].set),r=t[r]={__meta__:n,__name__:e,__type__:"property",__static__:!!o,get:_,set:c,configurable:!0},Object.defineProperty(t,e,r),r},d.defineMethod=function(t,e,n,o){var _="@"+e;return t[e]=n,t[_]={__meta__:n,__name__:e,__type__:"method",__static__:!!o}},d.defineBombMethod=function(n,t,o,_){t.split(",").forEach(function(t,e){d.defineMethod(n,t,o.call(n,t,e),_)})},d.defineMembers=function(n,o,t,_){d.forIn(t,function(t,e){-1<t.indexOf(",")?d.defineBombMethod(o,t,e,_):d["define"+n](o,t,e,_)})},u=1,f=0,l="nx.Anonymous",m.prototype={constructor:m,initMetaProcessor:function(){var t=this.meta,e=t.methods||{};d.mix(this.__class_meta__,{__type__:this.type,__meta__:t,__base__:this.base,__class_id__:u++,__method_init__:e.init||this.base.__method_init__,__static_init__:(t.statics||{}).init||this.base.__static_init__,__static__:!t.methods&&!!t.statics})},createClassProcessor:function(){var t=this;this.__class__=function(){this.__id__=f++,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 n=this.__class__;e.prototype=this.$base,n.prototype=new e,n.prototype.$base=this.$base,n.prototype.constructor=n},defineMethods:function(t,e){var n=e?"statics":"methods",o="__"+n+"__",_=e?this.__class__:this.__class__.prototype,s=(e?this.base:this.base.prototype)[o]||{};d.forIn(this.meta[n],function(t,e){s[t]&&"function"==typeof e&&(e.__base__=s[t])}),_[o]=d.mix(t[o],s,this.meta[n]),d.defineMembers("Method",_,_[o],e)},defineProperties:function(t){var e=t.__static__,n=e?this.__class__:this.__class__.prototype,o=e?this.base:this.base.prototype;n.__properties__=d.mix(null,o.__properties__,t.__properties__,this.meta.properties),d.defineMembers("Property",n,n.__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,n=this.__class_meta__;d.mix(t.prototype,n),d.mix(t,n),-1===e.indexOf(l)&&d.set(d.GLOBAL,e,t)},registerDebug:function(t){d.DEBUG&&(d.set(d,"__instances__."+(f-1),t),d.set(d,"__instances__.length",f))}},d.declare=function(t,e){e=new m("string"==typeof t?t:l+u,e||t);return e.initMetaProcessor(),e.createClassProcessor(),e.inheritProcessor(),e.methodsConstructorProcessor(),e.staticsConstructorProcessor(),e.registerProcessor(),e.__class__}}.call(this);