租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.4 KiB

3 months ago
  1. # define-data-property <sup>[![Version Badge][npm-version-svg]][package-url]</sup>
  2. [![github actions][actions-image]][actions-url]
  3. [![coverage][codecov-image]][codecov-url]
  4. [![License][license-image]][license-url]
  5. [![Downloads][downloads-image]][downloads-url]
  6. [![npm badge][npm-badge-png]][package-url]
  7. Define a data property on an object. Will fall back to assignment in an engine without descriptors.
  8. The three `non*` argument can also be passed `null`, which will use the existing state if available.
  9. The `loose` argument will mean that if you attempt to set a non-normal data property, in an environment without descriptor support, it will fall back to normal assignment.
  10. ## Usage
  11. ```javascript
  12. var defineDataProperty = require('define-data-property');
  13. var assert = require('assert');
  14. var obj = {};
  15. defineDataProperty(obj, 'key', 'value');
  16. defineDataProperty(
  17. obj,
  18. 'key2',
  19. 'value',
  20. true, // nonEnumerable, optional
  21. false, // nonWritable, optional
  22. true, // nonConfigurable, optional
  23. false // loose, optional
  24. );
  25. assert.deepEqual(
  26. Object.getOwnPropertyDescriptors(obj),
  27. {
  28. key: {
  29. configurable: true,
  30. enumerable: true,
  31. value: 'value',
  32. writable: true,
  33. },
  34. key2: {
  35. configurable: false,
  36. enumerable: false,
  37. value: 'value',
  38. writable: true,
  39. },
  40. }
  41. );
  42. ```
  43. [package-url]: https://npmjs.org/package/define-data-property
  44. [npm-version-svg]: https://versionbadg.es/ljharb/define-data-property.svg
  45. [deps-svg]: https://david-dm.org/ljharb/define-data-property.svg
  46. [deps-url]: https://david-dm.org/ljharb/define-data-property
  47. [dev-deps-svg]: https://david-dm.org/ljharb/define-data-property/dev-status.svg
  48. [dev-deps-url]: https://david-dm.org/ljharb/define-data-property#info=devDependencies
  49. [npm-badge-png]: https://nodei.co/npm/define-data-property.png?downloads=true&stars=true
  50. [license-image]: https://img.shields.io/npm/l/define-data-property.svg
  51. [license-url]: LICENSE
  52. [downloads-image]: https://img.shields.io/npm/dm/define-data-property.svg
  53. [downloads-url]: https://npm-stat.com/charts.html?package=define-data-property
  54. [codecov-image]: https://codecov.io/gh/ljharb/define-data-property/branch/main/graphs/badge.svg
  55. [codecov-url]: https://app.codecov.io/gh/ljharb/define-data-property/
  56. [actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/ljharb/define-data-property
  57. [actions-url]: https://github.com/ljharb/define-data-property/actions