decoratable
define decoratable function. like connect middleware.
Last updated 6 years ago by hrsh7th .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install decoratable 
SYNC missed versions from official npm registry.

decoratable

define decoratable function. like connect middleware.

example

var decoratable = require('decoratable');

/**
 * define class.
 */
function SomeClass(values) {
  this._values = values;
}

/**
 * get value.
 */
SomeClass.prototype.get = decoratable(function(key) {
  return this._values[key];
});

/**
 * decorate default value.
 */
SomeClass.prototype.get.use(function(key, next) {
  var v = next(key);
  if ((key === 'created' || key === 'updated') && v === undefined) {
    return Date.now();
  }
  return v;
});

/**
 * instantiate.
 */
var ins = new SomeClass({ created: 1234567890 });
ins.get('created'); //=> 1234567890
ins.get('updated'); //=> Date.now() results.

Current Tags

  • 0.0.2                                ...           latest (6 years ago)

2 Versions

  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |