Nodejs-Roadmap
Nodejs-Roadmap copied to clipboard
函数 - Node.js技术栈
https://www.nodejs.red/#/javascript/func
Description
- arguments.callee() 现在已经不推荐使用,建议换一个实现方式,比如像下面这样:
function factorial(num) {
return (function fn() {
if (num <= 1) {
return 1
} else {
return num-- * fn()
}
})()
}
console.log(factorial(3))
-
闭包中使用this对象将会导致的一些问题
这个部分,是不是可以用箭头函数来避免一些问题?
var box = {
user: 'zs',
getThis: function () {
return () => {
return this
}
}
}
console.log(box.getThis()()) // { user: 'zs', getThis: [Function: getThis] }