箭头函数和一般函数,for of for in
我们在使用箭头函数时,一定要记得和普通函数的区别,箭头函数时匿名函数,没有自己的arguments,this,super。特别注意arguments是一个伪数组,并没有数组的方法,唯二属性,callee(严格模式不可用),length
for in 可遍历的对象都可使用,返回key
for of 只能只用在可迭代对象上,返回值
const fn = () => {
console.log(arguments); //报错arguments is not defined
}
fn(1, 2, 3)
const fn = function (...a) {
console.log(a); //(3) ["a", "b", "c"]
}
fn('a', 'b', 'c')
const fn = function () {
console.log(arguments); //Arguments(3) [1, 2, 3, callee: (...), Symbol(Symbol.iterator): ƒ]
}
fn(1, 2, 3)
const fn = function () {
for (let i in arguments) {
console.log(i) //0 1 2
}
for (let j of arguments) {
console.log(j) //a b c
}
}
fn('a', 'b', 'c')