Introduction to Loadash Js and its `identity` property (part 1)
- 2019年11月22日
- 技術情報
What is Lodash
Lodash is a JavaScript library which provides utility functions for common programming tasks, delivering consistency, modularity and performance etc and it provides simple to use methods that solve common problems.
Why Lodash
- Provides consistent cross browser support.
- Able to use both for frontend & backend.
- Lodash can follow DRY principle.
- Performance and optimization for speed is better rather than native and more readable.
- Declarative type.
- Have good amount of contributors and active in their respositories.
- Support every browser basically.
How
- Can use locally or globally
- Can also go through with npm
- For backend use, have to require lodash in code.
I will introduce with a property called identity using in lodash js
Identity
var res = _.identity('hlaing', 'tin');
// res is hlaing
Method returns the first argument
_.identity in documentation of _.findKey and _.findLastKey
var data = {
topic: "lodash",
desc: "js library",
awesome: "chaining"
};
var keyRes = _.findKey(p); // returns "topic"
var lastKeyRes = _.findLastKey(p); // returns "awesome"
// same with above
var keyRes = _.findKey(p, _.identity);
var lastKeyRes = _.findLastKey(p, _.identity);
// which again means the same scenario:
var keyRes = _.findKey(p, function(x) { return x; }
var lastKeyRes = _.findLastKey(p, function(x) { return x; }
I introduced the identity property this week and will introduce the rest functionalities in coming weeks.
By Yuuma
yuuma at 2019年11月22日 10:00:42