Lodash教程

Lodash mixin method

语法

_.mixin([object=lodash], source, [options={}])
Adds all own enumerable string keyed function properties of a source object to the destination object. If object is a function, then methods are added to its prototype as well.

参数

[object=lodash] (Function|Object) − The destination object. source (Object) − The object of functions to add. [options={}] (Object) − The options object. [options.chain=true] (boolean) − Specify whether mixins are chainable.

输出

(Function) − Returns object.

实例

var _ = require('lodash');
function vowels(string) {
   return _.filter(string, function(v) {
      return /[aeiou]/i.test(v);
   });
}
_.mixin({ 'vowels': vowels }, { 'chain': false });
console.log(_('Julie').vowels());
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

[ 'u', 'i', 'e' ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4