Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/p-baleine/node-forwardable
node-forwardable
https://github.com/p-baleine/node-forwardable
Last synced: 21 days ago
JSON representation
node-forwardable
- Host: GitHub
- URL: https://github.com/p-baleine/node-forwardable
- Owner: p-baleine
- Created: 2012-07-16T06:53:49.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-08-22T22:58:16.000Z (about 12 years ago)
- Last Synced: 2024-10-14T22:31:06.636Z (24 days ago)
- Language: JavaScript
- Size: 154 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
node-forwardable
================Ruby's forwardable inspired module which defines delegatable functionality of methods for a class.
## Install
npm install forwardable## Example
var util = require('util')
, forwardable = require('../').forwardable
, log = console.log.bind(console);
var Queue = function() {
this.q = []; // prepare delegate object
};
util._extend(Queue, forwardable);
// setup preferred interface, enq() and deq()...
Queue.defDelegator('q', 'push', 'enq');
Queue.defDelegator('q', 'shift', 'deq');
// support some general Array methods that fit Queues well
Queue.defDelegators('q', 'push', 'shift');
var q = new Queue;
q.enq(1, 2, 3, 4, 5);
q.push(6);
log(q.shift()); //=> 1
while (q.q.length > 0) {
log(q.deq()); //=> 2, 3, 4, 5, 6
}