\hypertarget{md_sfcode_node_modules_d_README_autotoc_md7769}{}\doxysection{Property descriptor factory}\label{md_sfcode_node_modules_d_README_autotoc_md7769}
{\itshape Originally derived from \href{https://github.com/medikoo/es5-ext}{\texttt{ es5-\/ext}} package.}

Defining properties with descriptors is very verbose\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var Account = function () \{\};}
\DoxyCodeLine{Object.defineProperties(Account.prototype, \{}
\DoxyCodeLine{  deposit: \{}
\DoxyCodeLine{    value: function () \{}
\DoxyCodeLine{      /* ... */}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    configurable: true,}
\DoxyCodeLine{    enumerable: false,}
\DoxyCodeLine{    writable: true}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  withdraw: \{}
\DoxyCodeLine{    value: function () \{}
\DoxyCodeLine{      /* ... */}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    configurable: true,}
\DoxyCodeLine{    enumerable: false,}
\DoxyCodeLine{    writable: true}
\DoxyCodeLine{  \},}
\DoxyCodeLine{  balance: \{}
\DoxyCodeLine{    get: function () \{}
\DoxyCodeLine{      /* ... */}
\DoxyCodeLine{    \},}
\DoxyCodeLine{    configurable: true,}
\DoxyCodeLine{    enumerable: false}
\DoxyCodeLine{  \}}
\DoxyCodeLine{\}); }

\end{DoxyCode}


D cuts that to\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{var d = require("{}d"{});}
\DoxyCodeLine{}
\DoxyCodeLine{var Account = function () \{\};}
\DoxyCodeLine{Object.defineProperties(Account.prototype, \{}
\DoxyCodeLine{  deposit: d(function () \{}
\DoxyCodeLine{    /* ... */}
\DoxyCodeLine{  \}),}
\DoxyCodeLine{  withdraw: d(function () \{}
\DoxyCodeLine{    /* ... */}
\DoxyCodeLine{  \}),}
\DoxyCodeLine{  balance: d.gs(function () \{}
\DoxyCodeLine{    /* ... */}
\DoxyCodeLine{  \})}
\DoxyCodeLine{\}); }

\end{DoxyCode}


By default, created descriptor follow characteristics of native ES5 properties, and defines values as\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\{ configurable: true, enumerable: false, writable: true \} }

\end{DoxyCode}


You can overwrite it by preceding {\itshape value} argument with instruction\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{d("{}c"{}, value); // \{ configurable: true, enumerable: false, writable: false \}}
\DoxyCodeLine{d("{}ce"{}, value); // \{ configurable: true, enumerable: true, writable: false \}}
\DoxyCodeLine{d("{}e"{}, value); // \{ configurable: false, enumerable: true, writable: false \}}
\DoxyCodeLine{}
\DoxyCodeLine{// Same way for get/set:}
\DoxyCodeLine{d.gs("{}e"{}, value); // \{ configurable: false, enumerable: true \} }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_d_README_autotoc_md7770}{}\doxysubsection{Installation}\label{md_sfcode_node_modules_d_README_autotoc_md7770}
\begin{DoxyVerb}$ npm install d
\end{DoxyVerb}
 To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try\+: \href{http://browserify.org/}{\texttt{ Browserify}}, \href{https://github.com/medikoo/modules-webmake}{\texttt{ Webmake}} or \href{http://webpack.github.io/}{\texttt{ Webpack}}\hypertarget{md_sfcode_node_modules_d_README_autotoc_md7771}{}\doxysubsection{Other utilities}\label{md_sfcode_node_modules_d_README_autotoc_md7771}
\hypertarget{md_sfcode_node_modules_d_README_autotoc_md7772}{}\doxysubsubsection{auto\+Bind(obj, props) \+\_\+(d/auto-\/bind)\+\_\+}\label{md_sfcode_node_modules_d_README_autotoc_md7772}
Define methods which will be automatically bound to its instances


\begin{DoxyCode}{0}
\DoxyCodeLine{var d = require('d');}
\DoxyCodeLine{var autoBind = require('d/auto-\/bind');}
\DoxyCodeLine{}
\DoxyCodeLine{var Foo = function () \{ this.\_count = 0; \};}
\DoxyCodeLine{Object.defineProperties(Foo.prototype, autoBind(\{}
\DoxyCodeLine{  increment: d(function () \{ ++this.\_count; \});}
\DoxyCodeLine{\}));}
\DoxyCodeLine{}
\DoxyCodeLine{var foo = new Foo();}
\DoxyCodeLine{}
\DoxyCodeLine{// Increment foo counter on each domEl click}
\DoxyCodeLine{domEl.addEventListener('click', foo.increment, false); }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_d_README_autotoc_md7773}{}\doxysubsubsection{lazy(obj, props) \+\_\+(d/lazy)\+\_\+}\label{md_sfcode_node_modules_d_README_autotoc_md7773}
Define lazy properties, which will be resolved on first access


\begin{DoxyCode}{0}
\DoxyCodeLine{var d = require("{}d"{});}
\DoxyCodeLine{var lazy = require("{}d/lazy"{});}
\DoxyCodeLine{}
\DoxyCodeLine{var Foo = function () \{\};}
\DoxyCodeLine{Object.defineProperties(Foo.prototype, lazy(\{ items: d(function () \{ return []; \}) \}));}
\DoxyCodeLine{}
\DoxyCodeLine{var foo = new Foo();}
\DoxyCodeLine{foo.items.push(1, 2); // foo.items array created and defined directly on foo }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_d_README_autotoc_md7774}{}\doxysection{Tests $<$a href=\char`\"{}https\+://travis-\/ci.\+org/medikoo/d\char`\"{}$>$$<$img src=\char`\"{}https\+://travis-\/ci.\+org/medikoo/d.\+png\char`\"{} alt=\char`\"{}\+Build Status\char`\"{}/$>$$<$/a$>$}\label{md_sfcode_node_modules_d_README_autotoc_md7774}
\begin{DoxyVerb}$ npm test
\end{DoxyVerb}
 \hypertarget{md_sfcode_node_modules_d_README_autotoc_md7775}{}\doxysection{Security contact information}\label{md_sfcode_node_modules_d_README_autotoc_md7775}
To report a security vulnerability, please use the \href{https://tidelift.com/security}{\texttt{ Tidelift security contact}}. Tidelift will coordinate the fix and disclosure.

\DoxyHorRuler{0}


 {\bfseries{ \href{https://tidelift.com/subscription/pkg/npm-d?utm_source=npm-d&utm_medium=referral&utm_campaign=readme}{\texttt{ Get professional support for d with a Tidelift subscription}} }} ~\newline
 \textsubscript{ Tidelift helps make open source sustainable for maintainers while giving companies~\newline
assurances about security, maintenance, and licensing for their dependencies. }  