Please explain usage of _.identity(value) of underscore.js

前端 未结 3 1320
不知归路
不知归路 2021-01-17 08:05

Please explain usage of _.identity(value) of underscore.js. Not able to understand it from the documentation ( http://underscorejs.org/#identity ).

Can

3条回答
  •  暖寄归人
    2021-01-17 08:14

    It's essentially a no-operation function. It returns the value of whatever was passed into it.

    The part about it being used as a "default iterator" within the library itself means that in other functions which may have an optional "iterator" parameter (which is likely used as a function to apply to each element of an array of some kind), if no iterator parameter is passed, the library will use this "no-op" iterator instead and the elements of the array will remain unchanged.

提交回复
热议问题