Add computed properties to JavaScript objects.
(Table of contents generated by [verb])
Install with npm
$ npm i computed-property --save
npm test
var computedProperty = require('computed-property');
Add a computed property to an object. This updates the property when dependent properties are updated.
Params
obj
{Object}: Object to add the property to.property
{String}: Name of the property.dependencies
{Array}: Optional list of properties to depend on.getter
{Function}: Getter function that does the calculation.
Example
var computedProperty = require('computed-property');
var file = {
name: 'home-page',
ext: '.hbs',
dirname: 'views',
data: {
title: 'Home'
}
};
computedProperty(
// object
file,
// property name
'path',
// optional dependencies (may be deeply nested)
['name', 'ext', 'dirname', 'data.title'],
// getter function
function () {
return this.dirname + '/' + this.name + this.ext;
});
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Brian Woodward
Copyright © 2015 Brian Woodward Released under the MIT license.
This file was generated by verb-cli on July 13, 2015.