{"_id":"mixin","_rev":"14-fbe4e99ec79fa6cea334d050244d4d4c","name":"mixin","description":"Prototypical mixin layer","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"mixin","description":"Prototypical mixin layer","version":"0.1.0","author":{"name":"Lee Iverson","email":"leei@sociologi.ca"},"engines":{"node":">= 0.4.0"},"devDependencies":{"vows":">= 0.5.6"},"main":"./mixin.js","dependencies":{},"_id":"mixin@0.1.0","_engineSupported":true,"_npmVersion":"1.0.6","_nodeVersion":"v0.4.8","_defaultsLoaded":true,"dist":{"shasum":"8733370cbfe340defc93a899fe318d3508b7c152","tarball":"https://registry.npmjs.org/mixin/-/mixin-0.1.0.tgz","integrity":"sha512-TZwJcno2IqbXGDkJLTTK1K87K8I8o0qSCoF13QgSB1sJgxPsBrEaK6lRzsVokA0RloB/sFASmzhCay4qba5T7Q==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBYySVfEkfLYEk4dA+AuldfTa3PKCe0w9y5xUGPzKDLZAiEA9o4COPspVW8S7M53ZY7txbT73zOzlACc8JvTsTqtViQ="}]},"scripts":{}},"0.2.0":{"name":"mixin","description":"Prototypical mixin layer","version":"0.2.0","author":{"name":"Lee Iverson","email":"leei@sociologi.ca"},"engines":{"node":">= 0.4.0"},"devDependencies":{"vows":">= 0.5.6"},"main":"./mixin.js","readme":"# Mixin.js\n\nMixin is an easy way to repeatedly mix functionality into a prototypical\nJavaScript class. It automatically takes care of the combination of overriding\nprototype methods and invoking constructors. Moreover, it will notify a mixed\nin constructor that is has been mixed into another class. This can be used to\nconstruct dependent mixin hierarchies.\n\n## Installation\n\nUsing npm:\n\n    npm install mixin\n\n## Usage:\n\n\n    var mixin = require(\"mixin\");\n\n    function Foo() {\n    }\n\n    Foo.prototype = {\n       t1: function() { return 't1'; }\n    };\n\n    Foo = mixin(Foo, EventEmitter);\n\nthis is the equivalent of:\n\n    function Foo() {\n        EventEmitter.call(this);\n    }\n\n    Foo.prototype = Object.create(EventEmitter.prototype);\n\nexcept that I can define a full set of prototypes in the `Foo.prototype`\nstatement before I invoke the mixin.\n\n# Usage\n\n## mixin(base, mixed)\n\nThe call `mixin(base, mixed)` returns a new constructor that adds the\nprototype for `mixed` at the back of the prototype chain for `base` and\ninvokes the constructors for both `base` and `mixed` in reverse order. If\n`mixed` has function property `included`, then this function will be invoked\nwith `this = mixed` and the new constructor class as the single argument.\n\nA constructor to be mixed in cannot have a prototype chain of its own\n(i.e. it can't itself be the product of a mixin), however this functionality\ncan be achieved by calling mixin again inside the `included` callback.\nMoreover, the same constructor can not be mixed in twice to the same\nprototypical inheritance chain.\n\n## ctor.included(base)\n\nIf `ctor` is mixed in to another constructor (e.g. by invoking `mixin(Base, ctor)`) then `ctor.included(base)` is called with the `this` set to the mixed in constructor (e.g. `ctor`) and is passed a single argument, the new constructor created by `mixin()`.  This is extremely useful for creating dependent chains of mixins (i.e. `Mixin1` requires `Mixin2`) since `mixin` itself can be invoked from within the `included` call.\n\nIf `included` returns a value, then it is used as the constructor for the call to `mixin` that invoked this function.  This behavior leads to the useful idiom:\n\n    Foo.included = function(ctor) {\n        return mixin(ctor, EventEmitter);\n    }\n\nto mix the functionality of EventEmitter into any constructor that mixes in `Foo`.\n\n## mixin.alias(obj, name, suffix, fun)\n\nCan be used to override a method already defined on `obj`. It assigns `fun` to\n`obj[name+'_with_\"+suffix]` and reassigns the current value of `obj[name]` to\n`obj[name+'_without_'+suffix]`. Finally it sets `obj[name]` to `fun`.  This is\nsimilar to Rails' 'alias_method_chain`.\n","_id":"mixin@0.2.0","dist":{"shasum":"fb9db3d31175badb0a199dd4aad66476147b7d93","tarball":"https://registry.npmjs.org/mixin/-/mixin-0.2.0.tgz","integrity":"sha512-rG26haL24UI5gZEwUYjI4F57cghVUYvRdiN/7DjlbRu5DuXmx2sfmLqidYtP7Aq6C3xGvirRS+/ZtUQEgcO+Xw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDQ4R1KEoHTzkY0M/h+c1lsYJTDmJUZXFdx6LhXoZ8LpwIgK0LTBV11duDCWrEUcYIxM2q5QjdwKjjluecK7phZezE="}]},"maintainers":[{"name":"leei","email":"leei@sociologi.ca"}]}},"maintainers":[{"name":"leei","email":"leei@sociologi.ca"}],"time":{"modified":"2022-06-19T22:59:03.057Z","created":"2011-06-08T01:43:21.061Z","0.1.0":"2011-06-08T01:43:21.591Z","0.2.0":"2012-06-28T18:37:01.168Z"},"author":{"name":"Lee Iverson","email":"leei@sociologi.ca"},"users":{"pgilad":true,"techshed":true,"tarex":true,"brunolemos":true,"magicmind":true,"basilvalentine":true,"youzaiyouzai":true}}