0.0.2 • Published 9 years ago

specr v0.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
9 years ago

Installation

$ npm install specr

Example

var specr = require('specr');

function Obj(spec) {
    function noop() {};

    noop.prototype.bar = '...';
    noop.prototype.print = function() { console.log('bar'); };
    noop.prototype.getOptions = function() { return { someVar: 1 }; };

    specr(noop.prototype, spec, { foo: 'OVERRIDE', print: 'DEFINE_MANY', getOptions: 'DEFINE_MANY_MERGED' });

    return new noop();
}

var obj = new Obj({
   mixins: [{ print: function() { console.log('foo') } }],
   foo: 'bar',
   print: function() { console.log('baz') },
   getOptions: function() {
       return { anotherVar: 2 };
   }
});

obj.foo; // -> 'bar'
obj.print();  // -> 'foo' 'bar' 'baz'
obj.getOptions(); // -> { someVar: 1, anotherVar: 2 }

Authors

License

MIT

0.0.2

9 years ago

0.0.1

9 years ago