node-oops
Version:
A small library that makes object-oriented programming in javascript a little simpler.
1 lines • 4.03 kB
JavaScript
(function(e){"use strict";var t,n=function(e){return e.name},r,i=[],o=[];if(typeof global=="object"&&global){t=global;r=global.oops}else if(typeof window!=="undefined"){t=window;r=window.oops;if(typeof function u(){}.name=="undefined"){n=function(e){var t=e.toString().match(/^function\s*(?:\s+([\w\$]*))?\s*\(/);return t?t[1]:""}}}else{t={}}if(r){i.push(function(){if(t.oops===Define){t.oops=r;r=e}})}function dbc(e,t){e=Array.isArray(e)?e:[e];var n,r;for(n=0;n<e.length;n++){var i=e[n];r=typeof i==="function"?i():i;if(!r){t=t||"Failed contract requirement:".concat(i);throw new ContractError(typeof t==="function"?t():t)}}}function s(e,t,n,r){dbc([typeof t==="string"],"Invalid property name [String].");r=r||{};r.value=n;Object.defineProperty(e,t,r)}function f(e,t,n,r){dbc([!n||typeof n==="function"],"Invalid method [Function].");r=r||{};s(e,t,n,r)}function a(e,t,n,r,i){dbc([typeof t==="string"],"Invalid property name [String].");dbc([!n||typeof n==="function"],"Invalid getter [Function].");dbc([!r||typeof r==="function"],"Invalid setter [Function].");i=i||{};delete i.writable;if(n){i.get=n}if(r){i.set=r}Object.defineProperty(e,t,i)}function c(e,t,n){var r={};if(e===true){r.configurable=true}if(t===true){r.enumerable=true}if(n===true){r.writable=true}return r}function p(e){e=e||{};return c(e.configurable,e.enumerable,e.writable)}function Define(e,t){var n=e;if(!t&&typeof e.prototype==="object"&&typeof e.prototype.constructor==="function"){n=e.prototype}s(this,"_it",n);s(this,"_d",{})}Object.defineProperties(Define.prototype,{enumerable:{get:function(){this._d.enumerable=true;return this},enumerable:true},configurable:{get:function(){this._d.configurable=true;return this},enumerable:true},writable:{get:function(){this._d.writable=true;return this},enumerable:true},value:{value:function(e,t){s(this._it,e,t,p(this._d));return this},enumerable:true},method:{value:function(e,t){var r=typeof e;dbc([r==="string"||r==="function"],"Either the method or its name must be provided as the first argument.");if(r==="function"){dbc([typeof t==="undefined"],"When the method is given as first argument, additional arguments indicate an error on the part of the caller.");f(this._it,n(e),e,p(this._d))}else{dbc([typeof t!=="undefined"],"When the method's name is provided as the first argument the method must appear as the second.");f(this._it,e,t,p(this._d))}return this},enumerable:true},property:{value:function(e,t,r){var i=typeof e;dbc([i==="string"||i==="function"],"Either the property's name or it's getter [Function] must be provided as the first argument.");var o=this._d;if(i==="function"){a(this._it,n(e),e,t,p(this._d))}else{a(this._it,e,t,r,p(this._d))}return this},enumerable:true}});function h(e,t){e.super_=t;e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:false,writable:true,configurable:true}})}function l(e,t){return new Define(e||this,t)}if(Object.getOwnPropertyDescriptor(Object.prototype,"defines")){o.push("defines")}else{Object.defineProperties(Object.prototype,{defines:{get:l,configurable:true}});i.push(function(){delete Object.prototype.defines;o.push("defines")})}if(Object.getOwnPropertyDescriptor(Function.prototype,"inherits")){o.push("inherits")}else{Object.defineProperties(Function.prototype,{inherits:{value:function(t){h(this,t);this.inherits=e},configurable:true}});i.push(function(){delete Function.prototype.inherits;o.push("inherits")})}function d(e){return e&&o.indexOf(e)>=0}function m(){if(i){i.forEach(function(e){e()});i=null}return Define}function ContractError(e){ContractError.super_.call(this,e);new Define(this).value("message",e||"")}h(ContractError,Error);new Define(ContractError).configurable.enumerable.method(function b(){return"ContractError: ".concat(this.message)});new Define(Define,true).enumerable.method(dbc).method(Define).method(l).method(ContractError).method(h).method(m).method(d);if(typeof module!="undefined"&&module&&typeof exports=="object"&&exports&&module.exports===exports){module.exports=Define}else{t.oops=Define}})();