常用Lodash函数库的函数

项目中常用的

  • _.isEmpty(value)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    _.isEmpty(null);
    // => true

    _.isEmpty(true);
    // => true

    _.isEmpty(1);
    // => true

    _.isEmpty([1, 2, 3]);
    // => false

    _.isEmpty({ 'a': 1 });
    // => false
  • _.isEqual(value, other) 深层的比较

    1
    2
    3
    4
    5
    6
    7
    8
    var object = { 'a': 1 };
    var other = { 'a': 1 };

    _.isEqual(object, other);
    // => true

    object === other;
    // => false
  • bind 通常在react中绑定this实例

  • 做为装饰器,使用方法@Bind()

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    function greet(greeting, punctuation) {
    return greeting + ' ' + this.user + punctuation;
    }

    var object = { 'user': 'fred' };

    var bound = _.bind(greet, object, 'hi');
    bound('!');
    // => 'hi fred!'

    // Bound with placeholders.
    var bound = _.bind(greet, object, _, '!');
    bound('hi');
    // => 'hi fred!'
  • cloneDeep 深克隆

    贴一下lodash文档链接

    Lodash

-------------本文结束感谢您的阅读-------------