最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Invalid Calling Object, and Compatibility - Stack Overflow

programmeradmin8浏览0评论

In Internet Explorer 10, I have the following:

  /* 
   *   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
       . . .
   }

This has been working fine, but suddenly is giving me

SCRIPT65535: Invalid calling object

I have determined that if I check the box, Tools > Compatibility View Settings > [_] Display intranet sites in Compatibility View, the aliased function runs just fine, but if I clear that box, I get the error.

What is the reason? What is the specific issue that IE is responding to? Has aliasing functions like that been eliminated? Has there been some change to the way the 'document' object behaves?

In Internet Explorer 10, I have the following:

  /* 
   *   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
       . . .
   }

This has been working fine, but suddenly is giving me

SCRIPT65535: Invalid calling object

I have determined that if I check the box, Tools > Compatibility View Settings > [_] Display intranet sites in Compatibility View, the aliased function runs just fine, but if I clear that box, I get the error.

What is the reason? What is the specific issue that IE is responding to? Has aliasing functions like that been eliminated? Has there been some change to the way the 'document' object behaves?

Share Improve this question asked Feb 5, 2015 at 18:14 Brian WrenBrian Wren 3776 silver badges15 bronze badges 1
  • This topic has an outstanding explanation: stackoverflow./questions/1007340/… – Brian Wren Commented Feb 5, 2015 at 19:24
Add a ment  | 

2 Answers 2

Reset to default 2

I just posted this as an answer, but I don't see it. Trying again...

This topic has an outstanding answer:

JavaScript function aliasing doesn't seem to work

"getElementById()" is supposed to be called as a method and not as a function, i.e. with a context to be applied upon (the document, or to put it in Javascript terms, the "this" value), obtained by parsing the left-side of the expression ("document.").

In the past, the context was necessarily accessed as a free variable from the function, so maybe they decided to clean out their code. Since some other major browsers do not support this kind of aliasing, I guess they'd figure most people wouldn't mind.

发布评论

评论列表(0)

  1. 暂无评论