8

#yyds干货盘点# 【js学习笔记三十八】纯函数

 2 years ago
source link: https://blog.51cto.com/u_14476028/5328658
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

我是歌谣 我有个兄弟 巅峰的时候排名c站总榜19 叫前端小歌谣 曾经我花了三年的时间创作了他 现在我要用五年的时间超越他 今天又是接近兄弟的一天人生难免坎坷 大不了从头再来 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷

#yyds干货盘点# 【js学习笔记三十八】纯函数_执行过程_02
// 函数的返回结果只依赖于它的参数。
//函数执行过程里面没有副作用。

//第一条 函数的结果只能依赖他的参数 纯函数
function animal(name) {
console.log(this.name)
}
//第二条 不是纯函数
var father = 'father'
function animal(name) {
console.log(this.name + 'father')
}

//第三步 改变了外层的对象 不是纯函数
const a = 1
const foo = (obj, b) => {
obj.x = 2
return obj.x + b
}
const counter = { x: 1 }
foo(counter, 2) // => 4
counter.x // => 2

//    函数的返回结果只依赖于它的参数。
            //函数执行过程里面没有副作用。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK