1 # D - Property descriptor factory
3 _Originally derived from [es5-ext](https://github.com/medikoo/es5-ext) package._
5 Defining properties with descriptors is very verbose:
8 var Account = function () {};
9 Object.defineProperties(Account.prototype, {
10 deposit: { value: function () {
12 }, configurable: true, enumerable: false, writable: true },
13 whithdraw: { value: function () {
15 }, configurable: true, enumerable: false, writable: true },
16 balance: { get: function () {
18 }, configurable: true, enumerable: false }
27 var Account = function () {};
28 Object.defineProperties(Account.prototype, {
29 deposit: d(function () {
32 whithdraw: d(function () {
35 balance: d.gs(function () {
41 By default, created descriptor follow characteristics of native ES5 properties, and defines values as:
44 { configurable: true, enumerable: false, writable: true }
47 You can overwrite it by preceding _value_ argument with instruction:
49 d('c', value); // { configurable: true, enumerable: false, writable: false }
50 d('ce', value); // { configurable: true, enumerable: true, writable: false }
51 d('e', value); // { configurable: false, enumerable: true, writable: false }
53 // Same way for get/set:
54 d.gs('e', value); // { configurable: false, enumerable: true }
59 #### autoBind(obj, props) _(d/auto-bind)_
61 Define methods which will be automatically bound to its instances
65 var autoBind = require('d/auto-bind');
67 var Foo = function () { this._count = 0; };
68 autoBind(Foo.prototype, {
69 increment: d(function () { ++this._count; });
74 // Increment foo counter on each domEl click
75 domEl.addEventListener('click', foo.increment, false);
78 #### lazy(obj, props) _(d/lazy)_
80 Define lazy properties, which will be resolved on first access
84 var lazy = require('d/lazy');
86 var Foo = function () {};
88 items: d(function () { return []; })
92 foo.items.push(1, 2); // foo.items array created
104 You can easily bundle _D_ for browser with [modules-webmake](https://github.com/medikoo/modules-webmake)
106 ## Tests [![Build Status](https://travis-ci.org/medikoo/d.png)](https://travis-ci.org/medikoo/d)