Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem with some of the host objects (i.e. any non-native objects) in IE (and not only IE) is that they don't inherit from <code>Function.prototype</code> (and often neither from top level <code>Object.prototype</code>). Some host objects that <strong>might look like functions</strong> actually have nothing to do with functions except that they can be called. The fact that these objects don't inherit from <code>Function.prototype</code> means that they fail to be identified as functions with <code>instanceof</code> operator; that their constructor is not referencing <code>Function</code>; and that they lack all of the <code>Function.prototype.*</code> methods, such as <code>call</code> or <code>apply</code>. Even their internal [[Class]] property might not be that of "Function", as it is with any native object (note that [[Class]] can be inferred from the result of <code>Object.prototype.toString</code> value).</p> <p>This is actually expected, since <strong>host objects are not required</strong> to implement many things that native objects do (as per ECMA-262, 3rd ed.). It is perfectly allowed for a host object to, say, throw error on method invocation (e.g. <code>hostObject.hostMethod()</code>); or when passing it as an operand to standard operators like <code>delete</code> (e.g. <code>delete hostObject.hostMethod</code>). As you can see, it is also OK for callable host objects to NOT inherit from native <code>Function.prototype</code>. </p> <p>Such unpredictable (yet perfectly compliant) behavior is actually one of the main reasons why <strong>host objects augmentation is recommended against</strong>.</p> <p>But back to your <code>call</code> problem : )</p> <p>The thing about these "tricky" IE host objects is that they often implement internal [[Call]] method, and it is possible to invoke <code>call</code> and <code>apply</code> on them, although <strong>not directly</strong>.</p> <p>Here's a pattern to emulate <code>apply</code> invocation on an object that doesn't have it:</p> <pre><code>function f(){ return arguments }; Function.prototype.apply.call(f, null, [1,2,3]); // [1,2,3] </code></pre> <p><code>null</code> can be replaced with whatever context object should be called in, of course.</p> <p>And an example of <code>apply</code> invocation on host object that has no <code>call</code>:</p> <pre><code>// should work in IE6, even though `alert` has no `call` there Function.prototype.call.call(alert, window, 'test'); </code></pre> <p><strong>Applying it to your code</strong></p> <pre><code>// Calls Master.initialize borrowing from Function.prototype Function.prototype.apply.call(Master.initialize, Master, [1,"VC2"]); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload