{"name":"inherit","version":"2.2.2","description":"Inheritance module for Node.js and browsers","homepage":"https://github.com/dfilatov/node-inherit","keywords":["class","prototype","inheritance","mixins","static"],"author":{"name":"Dmitry Filatov","email":"dfilatov@yandex-team.ru"},"contributors":[{"name":"Dmitry Filatov","email":"dfilatov@yandex-team.ru"},{"name":"Sergey Belov","email":"peimei@ya.ru","url":"http://github.com/arikon"}],"repository":{"type":"git","url":"http://github.com/dfilatov/node-inherit.git"},"dependencies":{},"devDependencies":{"nodeunit":"0.8.0"},"main":"index","engines":{"node":">= 0.4.0"},"enb":{"sources":["lib/inherit.js"]},"bugs":{"url":"https://github.com/dfilatov/node-inherit/issues"},"_id":"inherit@2.2.2","dist":{"shasum":"3b5b3417d434f81a234d68f79612615e416244a3","tarball":"http://registry-npm.ywwl.com/inherit/download/inherit-2.2.2.tgz","integrity":"sha512-AKa/Qq2zcNljjpTrQbOvm5cANNrVOVSd/2aNY7XrZPO6W3p7jiD5R3eJZ6DP5N2N79lgq7BrQFXANi5OSUcYNQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDubsLEccWZmi52F6aAA2s0hgmvo+zGmvj1BEn9t311MwIhAIbXU31B6gjR6BIhdlzqhkbFhVBpT7vNPkCjGbkgLrnl"}],"size":4575,"noattachment":false,"key":"/inherit/-/inherit-2.2.2.tgz"},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"dfilatov","email":"dfilatov@yandex-team.ru"},"maintainers":[{"name":"dfilatov","email":"dfilatov@yandex-team.ru"}],"directories":{},"readme":"Inherit [![NPM version](https://badge.fury.io/js/inherit.png)](http://badge.fury.io/js/inherit)\n=======\nThis module provides some syntax sugar for \"class\" declarations, constructors, mixins, \"super\" calls and static members.\n\nGetting Started\n---------------\n### In Node.js ###\nYou can install using Node Package Manager (npm):\n\n    npm install inherit\n\n### In Browsers ###\n```html\n<script type=\"text/javascript\" src=\"inherit.js\"></script>\n```\nIt also supports RequireJS module format and [YM module](https://github.com/ymaps/modules) format.\n\nModule has been tested in IE6+, Mozilla Firefox 3+, Chrome 5+, Safari 5+, Opera 10+.\n\nSpecification\n-------------\n### Creating a base class ###\n````js\nFunction inherit(Object props);\n````\n### Creating a base class with static properties ###\n````js\nFunction inherit(\n    Object props,\n    Object staticProps);\n````\n### Creating a derived class ###\n````js\nFunction inherit(\n    Function BaseClass,\n    Object props,\n    Object staticProps);\n````\n### Creating a derived class with mixins ###\n````js\nFunction inherit(\n    [\n        Function BaseClass,\n        Function Mixin,\n        Function AnotherMixin,\n        ...\n    ],\n    Object props,\n    Object staticProps);\n````\n\nExample\n------------\n```javascript\nvar inherit = require('inherit');\n\n// base \"class\"\nvar A = inherit(/** @lends A.prototype */{\n    __constructor : function(property) { // constructor\n        this.property = property;\n    },\n\n    getProperty : function() {\n        return this.property + ' of instanceA';\n    },\n    \n    getType : function() {\n        return 'A';\n    },\n\n    getStaticProperty : function() {\n        return this.__self.staticProperty; // access to static\n    }\n}, /** @lends A */ {    \n    staticProperty : 'staticA',\n    \n    staticMethod : function() {\n        return this.staticProperty;\n    }\n});\n\n// inherited \"class\" from A\nvar B = inherit(A, /** @lends B.prototype */{\n    getProperty : function() { // overriding\n        return this.property + ' of instanceB';\n    },\n    \n    getType : function() { // overriding + \"super\" call\n        return this.__base() + 'B';\n    }\n}, /** @lends B */ {\n    staticMethod : function() { // static overriding + \"super\" call\n        return this.__base() + ' of staticB';\n    }\n});\n\n// mixin M\nvar M = inherit({\n    getMixedProperty : function() {\n        return 'mixed property';\n    }\n});\n\n// inherited \"class\" from A with mixin M\nvar C = inherit([A, M], {\n    getMixedProperty : function() {\n        return this.__base() + ' from C';\n    }\n});\n\nvar instanceOfB = new B('property');\n\ninstanceOfB.getProperty(); // returns 'property of instanceB'\ninstanceOfB.getType(); // returns 'AB'\nB.staticMethod(); // returns 'staticA of staticB'\n\nvar instanceOfC = new C();\ninstanceOfC.getMixedProperty() // returns \"mixed property from C\"\n```\n","publish_time":1401883497010,"_cnpm_publish_time":1401883497010,"dist-tags":{"latest":"2.2.7"}}