Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Article on DontEnum and OOJS

Reply
Thread Tools

Article on DontEnum and OOJS

 
 
dhtmlkitchen@gmail.com
Guest
Posts: n/a
 
      10-19-2007
I have an article online, but it's not officially linked yet. This
will be the first public link.

I've found tons of errors myself, and there's probably plenty more --
I just didn't find them yet.

I'd really like to get some review on this. Both technical and
editorial, but mostly technical.

The code examples are all plain green. I'll beautify them later (i do
this in my editor w/a regexp find/rep)

http://dhtmlkitchen.com/learn/js/enumeration/
=========================++++++++++++++++++++
+==========================

Enumeration and Object Oriented JavaScript

Who is this Article For?
This article is primarily intended for JavaScript library authors,
language implementors, language contributors.

Anyone who reads this article thoroughly will gain a deeper
understanding of how enumeration works in JavaScript, and how to deal
with language complications and cross browser issues.

For the TG1 group (who is writing ES4), my recommended changes from
ES3 to are notated as struck out and highlighted. My recommendations
reflect what I think should change from ECMAScript rev 3 to ECMAScript
rev 4.
Synopsis

This article is about the for in statement, how it is broken in IE,
and how to work around the problem.

Prototype Chain
The for in loop works with the prototype chain. In order to understand
how the for in loop really works, it is necessary to thoroughly
understand the prototype chain.

Constructor chaining affects the prototype chain, which affects
enumeration.
Borrowing Properties

Borrowing properties is taking properties of a supplier object and
using those properties as properties to receiver object. This is
usually done using a for in loop. Some examples demonsotrate
complications with the prototype chain and the problems caused by an
IE bug that I call the JScript DontEnum bug.

Borrowing properties is related to constructor chaining. Both can be
used as a solution to the problem of adding new behavior to a class.
The two are used sometimes interchangeably, and sometimes together.

Examples
I have included some real world code (YUI) and some examples of my
own. Most of the examples are abbreviated and to the point. The goal
is to explain JavaScript and programming techniques, which can be used
to create a real program. The examples display an understanding how
the prototype chain and enumeration come into play in real-world code.

This article is quite long. The top level sections should be read all
the way through, with the exception of the explanation of Creating a
Subclass, and Borrow methods using an Array. These sections don't have
any dependencies.

You can save paper by printing at a smaller scale (60%), and double
sided (if your printer supports that). Or, you can just read it on
your computer (I bet you knew that).

Tests
There are many live tests that you can and should run. The tests use
eval to run the textContent of the pre element in each example.

The tests show three things:

* How JavaScript works
* Browser bugs
* Issues with JavaScript

If a test does not have a browser table, it is because the test is
known to pass in every browser. If you encounter such test does not
pass, please email me.

If there are any false statements, or if you get a different result
than what is listed in a browser table, please send an email to me.

Browsers tested:
* Internet Explorer 7 (Windows)
* Mozilla Firefox 2 (Mac, Windows)
* Opera 9.2 (Mac, Windows)
* Safari 2 (Mac)
* Safari 3 (Windows, Webkit on Mac)

Many of the examples use String.nl

String.nl = /*@cc_on!@*/false ? "\r\n" : "\n";

Internet Explorer handles whitespace in unexpected ways. This caused
several problems with the examples in this article that use innerText
and innerHTML with the pre element (other elements could not be
supported). The odd line of code above is a workaround.

Each test is inside a pre. The test code is run in a closure to keep
the global namespace clean.

(function(){ // Closed testF scope.
// Example test code
})();

There is a small templating system that performs evaluation on
supplanted code marked by ${/*code*/}. This was necessary to
facilitate white box testing This is viewable in the source of this
document. The templating system uses a setInnerHTML function to deal
with Internet Explorer's whitespace problem.

 
Reply With Quote
 
 
 
 
Dr J R Stockton
Guest
Posts: n/a
 
      10-20-2007
In comp.lang.javascript message <
legroups.com>, Fri, 19 Oct 2007 07:43:00, ""
<> posted:
>
>The code examples are all plain green. I'll beautify them later (i do
>this in my editor w/a regexp find/rep)
>
>http://dhtmlkitchen.com/learn/js/enumeration/



I will not be reading it, because :

You have overridden my chosen settings for font face and size.
Your chosen font is sans-serif, and too small, and will not Zoom in IE6
(OK, a heading Zooms; but having part-Zoom is silly).
You force the width so that the lines are too long and have too many
words.

I did try, though, and had a thought re .toFixed examples, which also
applies in the newsgroup FAQ and elsewhere : the example inputs to
..toFixed could be changed to be such that Javascript stores them
exactly. It will then be more honestly obvious what the point at issue
is. 0.07 can become 0.0625. Since 1.1255 cannot be stored exactly, but
only as (I think)
+1.12549999999999994493293797859223559498786926269 53125
it should round down.

For ease of reading, a decimal point should always have at least one
digit on each side, if possible.

The pages seem so big that there probably should be a warning for dial-
up users but I could be wrong there as Open Office is downloading
currently.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
 
dhtmlkitchen@gmail.com
Guest
Posts: n/a
 
      10-20-2007
On Oct 20, 10:16 am, Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
> In comp.lang.javascript message <1192779780.785434.29...@q5g2000prf.goog
> legroups.com>, Fri, 19 Oct 2007 07:43:00, "dhtmlkitc...@gmail.com"
> <dhtmlkitc...@gmail.com> posted:
>
>
>
> >The code examples are all plain green. I'll beautify them later (i do
> >this in my editor w/a regexp find/rep)

>
> >http://dhtmlkitchen.com/learn/js/enumeration/

>
> I will not be reading it, because :
>
> You have overridden my chosen settings for font face and size.
> Your chosen font is sans-serif, and too small, and will not Zoom in IE6
> (OK, a heading Zooms; but having part-Zoom is silly).
> You force the width so that the lines are too long and have too many
> words.
>


ctrl+/- works fine in IE7 and all other browsers. I don't have IE6, so
I couldn't try it.

Zoom is amazing in Opera!


> I did try, though, and had a thought re .toFixed examples, which also
> applies in the newsgroup FAQ and elsewhere : the example inputs to
> .toFixed could be changed to be such that Javascript stores them
> exactly. It will then be more honestly obvious what the point at issue
> is. 0.07 can become 0.0625. Since 1.1255 cannot be stored exactly, but
> only as (I think)
> +1.12549999999999994493293797859223559498786926269 53125
> it should round down.
>

1.125499999999999944932937978592235594987869262695 3125 === 1.1255; //
true

A more useful, pragmatic result of 1.1255.toFixed(3) would be 1.126,
not 1.125. I believe that is the intent of the spec, but it falls
short, unfortunately. I think Safari had the right approach. It might
not be 100% compliant, but gets results that don't require mental
binary conversions.



There are 10 types of people in the world: Those who understand
binary, and those who don't...


> For ease of reading, a decimal point should always have at least one
> digit on each side, if possible.
>
> The pages seem so big that there probably should be a warning for dial-
> up users but I could be wrong there as Open Office is downloading
> currently.
>

Nah, no warnings. The pages are only about 10-12k after gzip. The
server response does seem pretty slow, though. I'm going to get a java
profiler for that.

I broke out a few examples into new pgs. I'll probably break out a few
more pgs. It seems that the pages are too long. I should break them
out and summarize.


> --
> (c) John Stockton, Surrey, UK. ?...@merlyn.demon.co.uk Turnpike v6.05 IE 6
> news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
> <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
> <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.



 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      10-21-2007
In comp.lang.javascript message <
oglegroups.com>, Sat, 20 Oct 2007 20:36:23, ""
<> posted:
>On Oct 20, 10:16 am, Dr J R Stockton <j...@merlyn.demon.co.uk> wrote:
>> In comp.lang.javascript message <1192779780.785434.29...@q5g2000prf.goog
>> legroups.com>, Fri, 19 Oct 2007 07:43:00, "dhtmlkitc...@gmail.com"
>> <dhtmlkitc...@gmail.com> posted:




>> >http://dhtmlkitchen.com/learn/js/enumeration/

>>
>> I will not be reading it, because :
>>
>> You have overridden my chosen settings for font face and size.
>> Your chosen font is sans-serif, and too small, and will not Zoom in IE6
>> (OK, a heading Zooms; but having part-Zoom is silly).
>> You force the width so that the lines are too long and have too many
>> words.
>>

>
>ctrl+/- works fine in IE7 and all other browsers. I don't have IE6, so
>I couldn't try it.
>
>Zoom is amazing in Opera!


Yes. But there are still a fixed number of words per line, so zooming
in soon reaches the screen width. The whole approach is too dirigiste.

>> I did try, though, and had a thought re .toFixed examples, which also
>> applies in the newsgroup FAQ and elsewhere : the example inputs to
>> .toFixed could be changed to be such that Javascript stores them
>> exactly. It will then be more honestly obvious what the point at issue
>> is. 0.07 can become 0.0625. Since 1.1255 cannot be stored exactly, but
>> only as (I think)
>> +1.12549999999999994493293797859223559498786926269 53125
>> it should round down.
>>

>1.12549999999999994493293797859223559498786926269 53125 === 1.1255; //
>true


Yes, but it remains true for substantial changes in the LHS : in
particular, 1.12550000000000005 === 1.1255 .

>A more useful, pragmatic result of 1.1255.toFixed(3) would be 1.126,
>not 1.125. I believe that is the intent of the spec, but it falls
>short, unfortunately. I think Safari had the right approach. It might
>not be 100% compliant, but gets results that don't require mental
>binary conversions.


Since 1.1255 is stored under-value, 1.1255.toFixed(3) should give 1.125.
IE6 gives 1.126, Opera 9.24 and Firefox 2.0.0.8 give 1.125 .

What should be said is that, if always getting the exact final digit
matters, one should only use quantities, including intermediates, that
can be represented exactly in IEEE Doubles. Input and output strings
can be adjusted accordingly, as strings.


>> --
>> (c
>> ne
>> <U
>> <U


Please read the FAQ about news reply formatting.

Consider Section 3(a) of the Uniform Time Act of 1966 (15 U.S.C.
260a(a)) !


You have :

var day = 1000 * 60 * 60 * 24;
var yesterday = new Date(new Date() -day );
var today = new Date();
var tomorrow = new Date(new Date() - (-day) );

The second and fourth of those lines are wrong, unless the code is not
to be used with certain date/time/place combinations. Without curing
that fault, the fourth line is better written as

var tomorrow = new Date(+new Date() + day);

One can avoid the creation of a second Object by
var D = new Date() ; D.setTime(+D + Day)
or
var D = new Date() ; D.setDate(D.getDate()+1)


In Opera, Ctrl-Alt-V finds errors.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)
 
Reply With Quote
 
Peter Michaux
Guest
Posts: n/a
 
      10-22-2007
On Oct 19, 12:43 am, "dhtmlkitc...@gmail.com" <dhtmlkitc...@gmail.com>
wrote:
> I have an article online, but it's not officially linked yet. This
> will be the first public link.
>
> I've found tons of errors myself, and there's probably plenty more --
> I just didn't find them yet.
>
> I'd really like to get some review on this. Both technical and
> editorial, but mostly technical.
>
> The code examples are all plain green. I'll beautify them later (i do
> this in my editor w/a regexp find/rep)
>
> http://dhtmlkitchen.com/learn/js/enumeration/


The article is very long and it seems like the article could be broken
into several smaller ones focused on one particular recommendation.
For example, the article talks about broken dontEnum in JScript and
also about the location of the JSON methods. Those seem like very
separate issues.

Peter

 
Reply With Quote
 
dhtmlkitchen@gmail.com
Guest
Posts: n/a
 
      10-22-2007
On Oct 21, 7:24 pm, Peter Michaux <petermich...@gmail.com> wrote:
> On Oct 19, 12:43 am, "dhtmlkitc...@gmail.com" <dhtmlkitc...@gmail.com>
> wrote:


>
> >http://dhtmlkitchen.com/learn/js/enumeration/

>
> The article is very long

Yes, 12 long pages + 2 popup examples! I really didn't want it to be
more than 3-4 pages.

and it seems like the article could be broken
> into several smaller ones focused on one particular recommendation.
> For example, the article talks about broken dontEnum in JScript and
> also about the location of the JSON methods. Those seem like very
> separate issues.
>

You're right.

I'm trying to get Nicholas to write a contrasting proposal. That way,
I could have a simple link;

* Alterate JSON Proposal

Instead of the lengthy (and irrelevant) JSON discussion.

Time for a thread on that...


> Peter



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
DontEnum with custom property xdevel1999 Javascript 1 05-15-2009 08:11 PM
OOJS Question vunet.us@gmail.com Javascript 1 06-28-2007 05:40 PM
Photo Albums and Article Archive - Unlimited and Free fibonaccigold@gmail.com Digital Photography 0 07-03-2006 09:24 AM
Defining a property with the DontEnum attribute Howard Jess Javascript 16 11-26-2005 05:28 PM
Article : Tlbexp .exe and Regasm.exe (.Net FrameWork Tools Series) Namratha Shah \(Nasha\) ASP .Net 0 11-05-2004 06:31 AM



Advertisments
 



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