{"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"]},"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.staticMember; // 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","readmeFilename":"readme.md","bugs":{"url":"https://github.com/dfilatov/node-inherit/issues"},"_id":"inherit@2.2.2","_shasum":"3b5b3417d434f81a234d68f79612615e416244a3","_from":"https://registry.npmjs.org/inherit/-/inherit-2.2.2.tgz","_resolved":"https://registry.npmjs.org/inherit/-/inherit-2.2.2.tgz"}