有没有angular.identity()用例的好例子? [英] Is there any good example of use cases for angular.identity()?

查看:88
本文介绍了有没有angular.identity()用例的好例子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据文档

 返回第一个参数的函数。在功能样式中编写代码时,此功能非常有用。 

我想知道在哪里可以找到这种用例的一个很好的例子 - 在函数式样中编写代码有角度的应用程序
谢谢

解决方案

来自AngularJS源代码的示例:

 函数转换器(transformFn,value){
return(transformationFn || angular.identity)(value);
};

解释:

c $ c> transformationFn 作为第一个参数提供,它将作为自己的参数与 value 一起调用。否则标识函数将被调用相同的值。



作为源代码提及:


在函数样式中编写代码时,此函数非常有用。

这意味着在函数式编程中没有全局变量,所以你总是必须通过/注入你需要的任何东西。


According to the documentation

A function that returns its first argument. This function is useful when writing code in the functional style.

I am wondering where I can find a good example of such use case - writing code in functional style in an angular app. Thanks

解决方案

Example from the AngularJS source code:

function transformer(transformationFn, value) {
  return (transformationFn || angular.identity)(value);
};

Explanation:

In case transformationFn is provided as first parameter, it will be called with value as it's own parameter. Otherwise identity function will be called with the same value.

As ng source code mentions:

This function is useful when writing code in the functional style.

What this means is that in functional programming there are no globals, so you always have to pass/inject in everything you need.

这篇关于有没有angular.identity()用例的好例子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆