项目原始demo,不改动
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
Repozitorijs ir arhivēts. Tam var aplūkot failus un to var klonēt, bet nevar iesūtīt jaunas izmaiņas, kā arī atvērt jaunas problēmas/izmaiņu pieprasījumus.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # D
  2. ## Property descriptor factory
  3. _Originally derived from [es5-ext](https://github.com/medikoo/es5-ext) package._
  4. Defining properties with descriptors is very verbose:
  5. ```javascript
  6. var Account = function () {};
  7. Object.defineProperties(Account.prototype, {
  8. deposit: { value: function () {
  9. /* ... */
  10. }, configurable: true, enumerable: false, writable: true },
  11. withdraw: { value: function () {
  12. /* ... */
  13. }, configurable: true, enumerable: false, writable: true },
  14. balance: { get: function () {
  15. /* ... */
  16. }, configurable: true, enumerable: false }
  17. });
  18. ```
  19. D cuts that to:
  20. ```javascript
  21. var d = require('d');
  22. var Account = function () {};
  23. Object.defineProperties(Account.prototype, {
  24. deposit: d(function () {
  25. /* ... */
  26. }),
  27. withdraw: d(function () {
  28. /* ... */
  29. }),
  30. balance: d.gs(function () {
  31. /* ... */
  32. })
  33. });
  34. ```
  35. By default, created descriptor follow characteristics of native ES5 properties, and defines values as:
  36. ```javascript
  37. { configurable: true, enumerable: false, writable: true }
  38. ```
  39. You can overwrite it by preceding _value_ argument with instruction:
  40. ```javascript
  41. d('c', value); // { configurable: true, enumerable: false, writable: false }
  42. d('ce', value); // { configurable: true, enumerable: true, writable: false }
  43. d('e', value); // { configurable: false, enumerable: true, writable: false }
  44. // Same way for get/set:
  45. d.gs('e', value); // { configurable: false, enumerable: true }
  46. ```
  47. ### Installation
  48. $ npm install d
  49. To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: [Browserify](http://browserify.org/), [Webmake](https://github.com/medikoo/modules-webmake) or [Webpack](http://webpack.github.io/)
  50. ### Other utilities
  51. #### autoBind(obj, props) _(d/auto-bind)_
  52. Define methods which will be automatically bound to its instances
  53. ```javascript
  54. var d = require('d');
  55. var autoBind = require('d/auto-bind');
  56. var Foo = function () { this._count = 0; };
  57. Object.defineProperties(Foo.prototype, autoBind({
  58. increment: d(function () { ++this._count; });
  59. }));
  60. var foo = new Foo();
  61. // Increment foo counter on each domEl click
  62. domEl.addEventListener('click', foo.increment, false);
  63. ```
  64. #### lazy(obj, props) _(d/lazy)_
  65. Define lazy properties, which will be resolved on first access
  66. ```javascript
  67. var d = require('d');
  68. var lazy = require('d/lazy');
  69. var Foo = function () {};
  70. Object.defineProperties(Foo.prototype, lazy({
  71. items: d(function () { return []; })
  72. }));
  73. var foo = new Foo();
  74. foo.items.push(1, 2); // foo.items array created and defined directly on foo
  75. ```
  76. ## Tests [![Build Status](https://travis-ci.org/medikoo/d.png)](https://travis-ci.org/medikoo/d)
  77. $ npm test