Re: Determining what prototype should be used for an object

On 11/14/14, 6:31 AM, Domenic Denicola wrote:
> Just to sharpen the discussion, it would help to give one example of each...

Sure.

Consider this testcase:

<iframe></iframe>
<pre>
</pre>
<script>
   function isFromGlobal(obj, global) {
     return obj instanceof global.Object;
   }
   function w(str) { document.querySelector("pre").textContent += str + 
"\n"; }

   onload = function() {
     var l = 
Document.prototype.querySelectorAll.call(frames[0].document, "x");
     w(isFromGlobal(l, frames[0]));
     w(isFromGlobal(l, window));
     var arr = Array.prototype.slice.call(new frames[0].Array);
     w(isFromGlobal(arr, frames[0]));
     w(isFromGlobal(arr, window));
   }
</script>

The output in Firefox, Chrome, and Safari (didn't test IE, but could if 
needed) is:

true
false
false
true

-Boris

Received on Friday, 14 November 2014 17:41:38 UTC