Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

副作用 #134

Open
lovelmh13 opened this issue Jul 26, 2021 · 2 comments
Open

副作用 #134

lovelmh13 opened this issue Jul 26, 2021 · 2 comments

Comments

@lovelmh13
Copy link
Owner

函数不会影响到与他无关的变量或者函数 (不会改变给外界的变量赋值)

函数或者表达式修改了它的 scope 之外的状态
函数或者表达式除了返回语句外还与外部世界或者它所调用的函数有明显的交互行为

可以查看:Effect Hook

vue 的 computed 也不允许有副作用(只能 return, 不能直接去修改值)

@lovelmh13
Copy link
Owner Author

没有副作用是说,除了变量定义的时候给出的初始值之外,其他表达式不会改变任何变量的值/程序运行的状态。一个函数/表达式的结果仅仅体现在其输入参数和返回值上,输入的参数相同,则返回值相同。除了用函数得到这个返回值之外,函数不会再有其他任何的作用。

像 js(除了haskell之外几乎所有的语言) 这种,满满的都是副作用呀,比如赋值语句呀,dom操作呀,都是。

@lovelmh13
Copy link
Owner Author

与副作用相对的就是-纯函数

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant