Lodash - 原型 plant 方法



語法

_.prototype.plant(value)

建立一個鏈序列克隆,並將值植入為包裝值。

引數

  • value (*) − 要種植的值。

輸出

  • (Object) − 返回新的 Lodash 包裝器例項。

示例

var _ = require('lodash');  
function square(n) {
   return n * n;
}
 
var wrapped = _([1, 2]).map(square);
var other = wrapped.plant([3, 4]);
 
console.log(other.value());
console.log(wrapped.value());

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

命令

\>node tester.js

輸出

[ 9, 16 ]
[ 1, 4 ]
lodash_seq.htm
廣告
© . All rights reserved.