Lodash toPlainObject method
语法
Converts value to a plain object flattening inherited enumerable string keyed properties of value to own properties of the plain object.
参数
value (*) − The value to convert.
输出
(Object) − Returns the converted plain object.
实例
var _ = require('lodash');
function Foo() {
this.b = 2;
}
Foo.prototype.c = 3;
console.log(_.assign({ 'a': 1 }, new Foo));
console.log(_.assign({ 'a': 1 }, _.toPlainObject(new Foo)));
Save the above program in
tester.js. Run the following command to execute this program.
Command
输出
{ a: 1, b: 2 }
{ a: 1, b: 2, c: 3 }