define-property

中文文档
2.0.2发布于 2018/01/27MITCommonJS近 30 天下载 1.9亿

Define a non-enumerable property on an object. Uses Reflect.defineProperty when available, otherwise Object.defineProperty.

原始使用文档
文档目录8 节
  1. Install
  2. Release history
  3. Usage
  4. About
  5. Related projects
  6. Contributors
  7. Author
  8. License

define-property NPM version NPM monthly downloads NPM total downloads Linux Build Status

Define a non-enumerable property on an object. Uses Reflect.defineProperty when available, otherwise Object.defineProperty.

Please consider following this project's author, Jon Schlinkert, and consider starring the project to show your :heart: and support.

Install

Install with npm:

$ npm install --save define-property

Release history

See the CHANGELOG for updates.

Usage

Params

  • object: The object on which to define the property.
  • key: The name of the property to be defined or modified.
  • value: The value or descriptor of the property being defined or modified.
var define = require('define-property');
var obj = {};
define(obj, 'foo', function(val) {
  return val.toUpperCase();
});

// by default, defined properties are non-enumberable
console.log(obj);
//=> {}

console.log(obj.foo('bar'));
//=> 'BAR'

defining setters/getters

Pass the same properties you would if using Object.defineProperty or Reflect.defineProperty.

define(obj, 'foo', {
  set: function() {},
  get: function() {}
});

About

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test
Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

You might also be interested in these projects:

  • assign-deep: Deeply assign the enumerable properties and/or es6 Symbol properies of source objects to the target… more | homepage
  • extend-shallow: Extend an object with the properties of additional objects. node.js/javascript util. | homepage
  • merge-deep: Recursively merge values in a javascript object. | homepage
  • mixin-deep: Deeply mix the properties of objects into the first object. Like merge-deep, but doesn't clone. | homepage

Contributors

| Commits | Contributor | | --- | --- | | 28 | jonschlinkert | | 1 | doowb |

Author

Jon Schlinkert

License

Copyright © 2018, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on January 25, 2018.

版本与发布记录

define-property 共发布 12 个版本,首次发布于 2015/08/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.2latest2018/01/278 年前
2.0.12018/01/268 年前
2.0.02017/11/278 年前
1.0.02017/04/209 年前
0.2.52015/08/3111 年前
0.2.32015/08/2911 年前

关于 define-property 的常见问题

define-property 是什么?

Define a non-enumerable property on an object. Uses Reflect.defineProperty when available, otherwise Object.defineProperty.

如何安装 define-property?

在项目目录运行 npm install define-property,或使用 pnpm add / yarn add / bun add。

define-property 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/define-property 是否存在。

define-property 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

define-property 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=0.10.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

define-property 可以商用吗?

define-property 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

define-property 的下载量有多少?

根据 npm 官方下载统计,define-property 在 2026/10/05 – 2026/11/03 这 30 天内被下载 187,498,172 次,日均约 6,249,939 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

define-property 还在维护吗?

最新版本 2.0.2 发布于 2018/01/27(8 年前);至今共发布 12 个版本,其中过去 12 个月发布了 0 个;首次发布于 2015/08/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。