为啥 document.getElementsByTagName 等方法无法赋给一个变量

Function.prototype.apply()
■网友
估计其内部绑定了this,所以你可以使用,call或者applygTag.call(document,...)gTag.apply(document,...)或者使用bind绑定documentgTag = document.getElementByTagName.bind(document).
■网友
document.getElementBytagname中的上下文为document,是基于document向下查找,你的赋值只是将document的方法函数赋给变量,此时上下文为window,想使用就得像楼上所说那样改变执行上下文,用.call(document)改变他的执行上下文,就可以找到


    推荐阅读