this 是一个隐藏参数
arugments 是一个普通参数
我们要最先知道 this 的指向在函数定义的时候确定不了,只有在函数执行的时候才能确定。也就是说this最终指向调用它的对象。
function fn(){console.log(arguments);console.log(this);}fn.call(1,2,3)// 输出// Arguments(2) [2, 3, callee: ƒ, Symbol(Symbol.iterator): ƒ]// Number {1}
这里this就是 call()里面的一个数,它是一个数字1。
function fn(){console.log(arguments);console.log(this);}fn.call(undefined,1,2,3)// 输出// Arguments(3) [1, 2, 3, callee: ƒ, Symbol(Symbol.iterator): ƒ]// Window {window: Window, self: Window, document: document, name: "", location: Location, …}
这里的this 没有被定义 他就会默认指向上一层对象 也就是window对象。
