Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 130|回复: 0

Price price number number

[复制链接]

1

主题

1

帖子

5

积分

新手上路

Rank: 1

积分
5
发表于 2023-12-21 18:49:09 | 显示全部楼层 |阅读模式
The risk of race condition is reduced for the results of deterministic functions you can use the memoization mechanism tests for deterministic functions are much easier to write and maintain instead of calling them the equivalent can be passed to the target in the form of their result referential transparency which may be useful when refactoring debugging or experimenting with the code in case of errors the process of debugging and fixing the code will usually be easier and faster. Below you will find an example of a trivial function that meets the described requirements.

const vat number . function calculate    return price + price vat   const price number const price number con calculate Price price price console. log calculatePrice price price Both the repeatability condition and the lack of side Phone Number List effects condition were met. The example below is a classic example of the impure function. const user Record<string unknown>   id username 'admin' password ' '   function hidePassword user Record<string unknown> Record<string unknown>   delete usssword return user   consg hide Password user user The function shown is an impure function because it does not satisfy the no side effects condition. The function hide Passwor dmodifies the input object.




This happens because a reference to the object has been passed so that modifying the object inside the function f the transferred user. const user Record<string unknown>   id username 'admin' password ' '   function hidePassword user Record<string unknown> Record<string unknown>   const   password ...userCopy   user return userCopy   console.log hidePassword user user My case with nex . . caused my project to start getting database connection authentication errors. It is worth mentioning that in my code  was not the only source of database queries and all database clients used the same access data. A little investigation led me to the conclusion that the function that created the Knex instance had mistakenly become the impure function.

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2024-11-23 12:57 , Processed in 0.646902 second(s), 8 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表