Skip to content

toPlainObject

js
_.toPlainObject(value)

value 转换为普通对象,将 value 继承的可枚举字符串键属性展平为普通对象的自身属性。

¥Converts value to a plain object flattening inherited enumerable string keyed properties of value to own properties of the plain object.

新增于

¥Since

3.0.0

参数

¥Arguments

  1. value (*):要转换的值。

    ¥value ()*: The value to convert.

返回

¥Returns

(对象):返回转换后的纯对象。

¥(Object): Returns the converted plain object.

示例

¥Example

js
function Foo() {
  this.b = 2;
}

Foo.prototype.c = 3;

_.assign({ 'a': 1 }, new Foo);
// => { 'a': 1, 'b': 2 }

_.assign({ 'a': 1 }, _.toPlainObject(new Foo));
// => { 'a': 1, 'b': 2, 'c': 3 }

Lodash v4.17 中文网 - 粤ICP备13048890号