Windows Vista Tips

Windows Vista Tips > Newsgroups > Internet Explorer > javascript BUG: delete before for in statements breakes prototype.

Reply
Thread Tools Display Modes

javascript BUG: delete before for in statements breakes prototype.

 
 
_JM_
Guest
Posts: n/a

 
      02-03-2010
I wrote a piece of code that shows the problem.
When you delete a member of an object with a delete operator, you should be
able to see the prototype's value of the same property name if it exists
(because of chaining).

This works fine unless you try to do a for in statement of the object after
the delete, in which case the value of the prototype is not returned, in fact
it's never retrieved at all.

The example has two instances of Bar, both of them should have 3 members
before and after the delete, but after the delete only 2 members are found on
one of the instances.

This very example works fine in all other browsers (Firefox, Chrome, Opera).
If you do almost anything with the bar variable after the delete an before
the for in (for example uncomment the comparation bar==0) then the for in
statement works fine, just like it should always work.

This bug could produce some very serious problems on code that would seem to
work under most common cirumstances.

Here's the code:

str="";
var display = function(nombre, obj)
{
var i = 0;
str+=("<br/>"+nombre+"<br/>");
for (var a in obj){
str+=("&nbsp&nbsp "+a + "="+ obj[a]+"<br/>");
i++;
}
str+=("<br/>"+i+"<br/>");
}

var Bar = function()
{
this.instMember = "bar";
}

Bar.prototype.name = "proto";
Bar.prototype.id = 3;

bar = new Bar();
bar2 = new Bar();
bar.name = "inst";

//display objects before delete
display("bar", bar);
display("bar2", bar2);

str+=("<br/>----- delete bar.name<br/>");
delete bar.name;
//bar==0;

//display objects after delete
display("bar", bar);
display("bar2", bar2);

document.write(str);


----------------
This post is a suggestion for Microsoft, and Microsoft responds to the
suggestions with the most votes. To vote for this suggestion, click the "I
Agree" button in the message pane. If you do not see the button, follow this
link to open the suggestion in the Microsoft Web-based Newsreader and then
click "I Agree" in the message pane.

http://www.microsoft.com/communities...plorer.general
 
Reply With Quote
 
 
 
 
PA Bear [MS MVP]
Guest
Posts: n/a

 
      02-03-2010
MSDN IE Development Forum (post such questions here instead)
http://social.msdn.microsoft.com/For...opment/threads


_JM_ wrote:
> I wrote a piece of code that shows the problem.
> When you delete a member of an object with a delete operator, you should
> be
> able to see the prototype's value of the same property name if it exists
> (because of chaining).
>
> This works fine unless you try to do a for in statement of the object
> after
> the delete, in which case the value of the prototype is not returned, in
> fact it's never retrieved at all.
>
> The example has two instances of Bar, both of them should have 3 members
> before and after the delete, but after the delete only 2 members are found
> on one of the instances.
>
> This very example works fine in all other browsers (Firefox, Chrome,
> Opera).
> If you do almost anything with the bar variable after the delete an before
> the for in (for example uncomment the comparation bar==0) then the for in
> statement works fine, just like it should always work.
>
> This bug could produce some very serious problems on code that would seem
> to
> work under most common cirumstances.
>
> Here's the code:
>
> str="";
> var display = function(nombre, obj)
> {
> var i = 0;
> str+=("<br/>"+nombre+"<br/>");
> for (var a in obj){
> str+=("&nbsp&nbsp "+a + "="+ obj[a]+"<br/>");
> i++;
> }
> str+=("<br/>"+i+"<br/>");
> }
>
> var Bar = function()
> {
> this.instMember = "bar";
> }
>
> Bar.prototype.name = "proto";
> Bar.prototype.id = 3;
>
> bar = new Bar();
> bar2 = new Bar();
> bar.name = "inst";
>
> //display objects before delete
> display("bar", bar);
> display("bar2", bar2);
>
> str+=("<br/>----- delete bar.name<br/>");
> delete bar.name;
> //bar==0;
>
> //display objects after delete
> display("bar", bar);
> display("bar2", bar2);
>
> document.write(str);
>
>
> ----------------
> This post is a suggestion for Microsoft, and Microsoft responds to the
> suggestions with the most votes. To vote for this suggestion, click the "I
> Agree" button in the message pane. If you do not see the button, follow
> this
> link to open the suggestion in the Microsoft Web-based Newsreader and then
> click "I Agree" in the message pane.
>
> http://www.microsoft.com/communities...plorer.general


 
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An unknown error has occurred! Agnes M Windows Vista Mail 35 08-06-2010 10:36 PM
Can't delete restore point folders DWalker Windows Vista File Management 0 11-13-2007 06:02 PM
Can't delete a video file from desktop nLinked Windows Vista File Management 3 07-26-2007 03:13 PM
Re: Can't Delete Contacts in Windows Contact List ... WHY? R. C. White Windows Vista File Management 0 06-12-2007 03:15 PM
Re: Upgraded to AS 4.5, how do I delete old partnership? Mark ActiveSync 0 03-17-2007 01:34 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59