Newsgroups: comp.lang.javascript
From: "Douglas Crockford" <nos...@laserlink.net>
Date: Tue, 23 Sep 2003 17:10:07 -0700
Local: Tues, Sep 23 2003 8:10 pm
Subject: Re: myArray instanceof Array fails after passing to a different page
> I have a page with a series of child pages loaded into an iframe. When I When you say 'Array', you are talking about 'window.Array'. 'window' is the > move from page to page, I store an object containing the child's control > data in a variable on the main page, then use that data to populate the > controls when the child page is opened again. > One of these objects contains an Array, and the page reloads fine using > By checking "myArray instanceof Array", I have determined that the object > Does anybody know why this is? And/Or how I can get around it? browser's context object, and you get one per page (or frame). All of the arrays created within a context will have their constructor property set to 'window.Array'. An array created in a different context has a different window.Array, so your myArray instanceof Array fails. The ECMAScript standard does not discuss multiple contexts, even though typeof myArray == 'array' except that unfortunately, it turns out that typeof myArray == 'object' which not very useful. You might try testing for the presence of a well-know array method. typeof myArray.sort == 'function' This is not infallible, but it is better than the useless instanceof operator. You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||
