Lodash - toPlainObject 方法



語法

_.toPlainObject(value)

將值轉換為樸實物件,並將值繼承的可列舉字串鍵屬性展平成樸實物件的自身屬性。

引數

  • value (*) - 要轉換的值。

輸出

  • (物件) - 返回轉換後的樸實物件。

示例

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)));

將上述程式儲存在 tester.js 中。執行以下命令執行此程式。

命令

\>node tester.js

輸出

{ a: 1, b: 2 }
{ a: 1, b: 2, c: 3 }
lodash_lang.htm
廣告
© . All rights reserved.