still, even if NodeList will inherit from Array, the cross frame problem will fail in any case 'cause toString.call(querySelectorAll()) will not produce same as toString.call([]) neither will be instanceof Array or instanceof NodeList
Here the very last fallback to check the length property may become handy ... then we have Safari that consider querySelectorAll() and getElementsByTagName() as typeof "function" ... so, since there's no universal way to understand if that [[Class]] in the other frame is treatable as an Array, I don't see any fully trustable solution that works everywhere ... as developer, we should understand in advance what's iterable as an Array and what is not, specially because we create that frame or theoretically, we should never have access to it and through postMessage, as example, no way to pass an Array that is not recognizable as an Array in the current environment ( passed as string, created once received as Array ) Anyway, here my last "isArrayLike" implementation: https://gist.github.com/2294934 I should probably consider to check agains toString.call(obj) === nodeListClass then some browser may pass childNodes or getElementsByTagName and implement something different from static NodeList behind the scene ... Last, but not least, *never* had this problem in all these years, if you pass nodes between frames ... ask yourself why you need that in first place then control them the way you want, too much magic will miserably fail here and there quite randomly, imho. P.S. instanceof is simply fast and 99% of the time what's needed for that task On Tue, Apr 10, 2012 at 5:53 PM, John J Barton <[email protected]>wrote: > > > On Mon, Apr 9, 2012 at 9:17 PM, Andrea Giammarchi < > [email protected]> wrote: > >> I keep finding the frame problem overrated, specially in this case where >> the case you are passing DOM nodes between frames is ... well, extremely >> edge? > > > The frame problem might appear overrated if you imagine that DOM nodes > need to be "passed" between frames. But accessing an iframe's DOM nodes is > trivial property lookup, theFrame.contentWindow.querySelector(...). That > simplicity plus the experience of no significant issues in operating on the > iframe content encourages this usage pattern. Mostly devs avoid instanceof, > but eventually you end up using instanceof on an array. Nothing noticeable > happens when you do, other than your app is broken. Once you track it down > you are totally convinced that the browser is busted because the instanceof > test fails. You waste a day writing a test case to prove it. > > So this iframe problem is rare but hits very hard: you already have a big > investment in some code and you have to work hard to figure out what went > wrong. > > jjb >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

