@jswork/next
Version:
A javascript OOP toolkit for mobile & modern web.
1 lines • 6.98 kB
JavaScript
!function(){var a,i,s,o,e,r,n,_,c,u,f,p,t="object"==typeof global&&global&&global.Object===Object&&global,l="object"==typeof self&&self&&self.Object===Object&&self,t=t||l||Function("return this")(),l="object"==typeof exports&&exports&&!exports.nodeType&&exports,h=l&&"object"==typeof module&&module&&!module.nodeType&&module,d=t.nx=t.nx||{BREAKER:{},NIL:{},VERSION:"1.3.4",DEBUG:!1,GLOBAL:t};function y(t){return t.toString().replace(n,".$1").replace(_,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,h.exports.default=d,h.exports.nx=d,l.nx=d):t.nx=d,a=".",i="number",s="undefined",o=Array.prototype,e=Object.prototype.toString,r=Object.prototype.hasOwnProperty,n=/\[(\w+)\]/g,_=/[.]+/g,c=/^\.|\.$/g,d.noop=function(){},d.typeof=function(t){return null===t?"null":void 0===t?"undefined":"object"!=typeof t?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,s=0;s<o&&e.call(n,t[s],s,t)!==d.BREAKER;s++);},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 s.call(_,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,s=e.length;o<s;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),s=t||d.GLOBAL,_=o.length-1,e=o[_],i=0;i<_;i++)var r=o[i],c=isNaN(+o[i+1])?{}:[],s=s[r]=s[r]||c;return s[e]=n,t},d.get=function(e,t,n){var o;return t?Array.isArray(t)?t.map(function(t){return d.get(e,t,n)}):(t=y(t).split(a),o=e||d.GLOBAL,t.forEach(function(t){o=o&&o[t]}),typeof n!=s&&typeof o==s?n:o):e},d.del=function(t,e){for(var n=y(e).split(a),o=0;o<n.length;o++){var s=n[o];if(o===n.length-1)return null!=t&&("object"==typeof t&&delete t[s],!0);t=t[s]}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__+"]"}},l={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__,s=["get","set"][n.length];switch(e){case"method":return o[t].apply(this,n);case"property":return o["@"+t][s].apply(this,n)}}}),d.mix(h.__statics__,l),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?(_=c.value,i="_"+e,s=function(){return i in this?this[i]:d.isFunction(_)?_.call(this):_},function(t){this[i]=t}):(s=n.get||t[r]&&t[r].get||d.noop,n.set||t[r]&&t[r].set||d.noop);return r in t&&(s.__base__=t[r].get,c.__base__=t[r].set),r=t[r]={__meta__:n,__name__:e,__type__:"property",__static__:!!o,get:s,set:c,configurable:!0},Object.defineProperty(t,e,r),r},d.defineMethod=function(t,e,n,o){var s="@"+e;return t[e]=n,t[s]={__meta__:n,__name__:e,__type__:"method",__static__:!!o}},d.defineBombMethod=function(n,t,o,s){t.split(",").forEach(function(t,e){d.defineMethod(n,t,o.call(n,t,e),s)})},d.defineMembers=function(n,o,t,s){d.forIn(t,function(t,e){-1<t.indexOf(",")?d.defineBombMethod(o,t,e,s):d["define"+n](o,t,e,s)})},u=1,f=0,p="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+"__",s=e?this.__class__:this.__class__.prototype,_=(e?this.base:this.base.prototype)[o]||{};d.forIn(this.meta[n],function(t,e){_[t]&&"function"==typeof e&&(e.__base__=_[t])}),s[o]=d.mix(t[o],_,this.meta[n]),d.defineMembers("Method",s,s[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(p)&&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.define=function(t,e){e=new m("string"==typeof t?t:p+u,e||t);return e.initMetaProcessor(),e.createClassProcessor(),e.inheritProcessor(),e.methodsConstructorProcessor(),e.staticsConstructorProcessor(),e.registerProcessor(),e.__class__},d.declare=d.define}.call(this);