无效的调用对象和兼容性
Invalid Calling Object, and Compatibility
在 Internet Explorer 10 中,我有以下内容:
/*
* Alias document.getElementById(), to reduce typing, improve
* readability and speed up access to the function.
*/
var getElmById = document.getElementById;
function . . . (ctlID) {
var ctrl = getElmById(ctlID); // <————<<< error raised here
. . .
}
这一直工作正常,但突然给了我
SCRIPT65535: Invalid calling object
我已经确定,如果我选中该框,Tools > Compatibility View Settings > [_] Display intranet sites in Compatibility View
,别名函数运行得很好,但如果我清除该框,我就会收到错误消息。
这是什么原因? IE响应的具体问题是什么?这样的别名功能是否已被消除? 'document' 对象的行为方式是否发生了一些变化?
"getElementById()" 应该作为方法而不是函数调用,即具有要应用的上下文(文档,或者用 Javascript 术语表示,"this" value), 解析表达式左边得到("document.").
过去,上下文必须作为函数中的自由变量访问,因此他们可能决定清理代码。由于其他一些主要浏览器不支持这种别名,我猜他们认为大多数人不会介意。
我只是将此作为答案发布,但我没有看到它。重试...
这个话题有一个优秀的答案:
JavaScript function aliasing doesn't seem to work
在 Internet Explorer 10 中,我有以下内容:
/*
* Alias document.getElementById(), to reduce typing, improve
* readability and speed up access to the function.
*/
var getElmById = document.getElementById;
function . . . (ctlID) {
var ctrl = getElmById(ctlID); // <————<<< error raised here
. . .
}
这一直工作正常,但突然给了我
SCRIPT65535: Invalid calling object
我已经确定,如果我选中该框,Tools > Compatibility View Settings > [_] Display intranet sites in Compatibility View
,别名函数运行得很好,但如果我清除该框,我就会收到错误消息。
这是什么原因? IE响应的具体问题是什么?这样的别名功能是否已被消除? 'document' 对象的行为方式是否发生了一些变化?
"getElementById()" 应该作为方法而不是函数调用,即具有要应用的上下文(文档,或者用 Javascript 术语表示,"this" value), 解析表达式左边得到("document.").
过去,上下文必须作为函数中的自由变量访问,因此他们可能决定清理代码。由于其他一些主要浏览器不支持这种别名,我猜他们认为大多数人不会介意。
我只是将此作为答案发布,但我没有看到它。重试...
这个话题有一个优秀的答案:
JavaScript function aliasing doesn't seem to work