JS关于this指向的小练习

请阅读以下代码:
var obj = {};
obj.log = console.log;
obj.log.call(console, this)
该代码在浏览器中执行,输出的日志结果是什么?

这道题就是问console.log.call(console,this)打印出什么,这道题很容易引导人走向误区,因为我们知道call方法就是改变this的指向,但是这个被改变的this是log函数体内的this,而不是题目中作为参数传入的this,作为参数的这个this是指向window的。

 
posted @ 2018-06-20 20:25  mino1996  阅读(167)  评论(0编辑  收藏  举报