How Internet Explorer 8 document mode affects JavaScript - NicholasZakas

G

Garrett Smith

In doing research on JSON, I performed a search for `JSON undefined in
IE8`, I came upon familiar blog and found the entry had some information
that jumped out as being wrong.

I decided to leave a comment, but coming back several days later, I
found the comment was not approved. I emailed the author but I got no reply.

I saw the author is on Twitter, posting various things, so it is not as
if he is too busy. I sent a message on twitter, too:
http://twitter.com/dhtmlkitchen/status/16364046076

He did not reply, but posted another tweet right away:
http://twitter.com/slicknet/status/16364630527

I'm annoyed by both the misinformation and the censorship of a perfectly
well-intentioned reply.

I actually saved my comments in a file. Just in case.

| Internet Explorer 8’s JScript engine implements the native JSON
| object object as defined by ECMAScript 5. The object is only present,
| however, when the page is running in IE8 document mode. This includes
| the global JSON object as well as methods used for JSON functionality:
|
| * Date.prototype.toJSON()
| * Number.prototype.toJSON()
| * String.prototype.toJSON()
| * Boolean.prototype.toJSON()

Wrong! Only Date.prototype.toJSON is defined in ES5 and a simple:
alert(true.toJSON) shows that it's not in IE8, either.

The article then states:

| There’s a small group of fixes that can’t really be logically
| categorized but nonetheless help JScript come more into agreement
| with other JavaScript implementations. The first is that object
| literals now allow trailing commas. Prior to Internet Explorer 8, the
| following would cause a parse error:
|
| var object = {
| name: "value",
| };
|
|
| The trailing comma after the last property value is explicitly
| allowed by ECMAScript 3 syntax and is allowed in all other browsers.
| IE8 document mode now also supports this syntax correctly (other
| document modes still throw the error).

That's not true either. I explained in my comment that a trailing comma
in an ObjectLiteral is not provided for in the grammar of ECMAScript Ed.
3, that it is allowed in Ed 5, that its existence in Ed 5 is a
codification of existing behavior and that those are the reasons for IE8
allowing it.

But I noticed on the author's site:
| Note: Comments are heavily moderated. Please do not post spam. Please
| keep the comments on-topic. Please do not post unrelated questions or
| large chunks of code. Please be kind and keep the conversation civil
| and professional. Comments that are rude, off-topic, or don't have a
| valid email address are deleted.

My comment was not spam, was on-topic, and did not contain "large chunks
of code". It was civil and professional. I saved the comment to a file,
actually and so I can post it right here. I've only fixed one tiny typo
and not changed anything else.

Here are my unapproved comments:
| <blockquote>
| The trailing comma after the last property value is explicitly
| allowed by ECMAScript 3 syntax and is allowed in all other browsers.
| IE8 document mode now also supports this syntax correctly (other
| document modes still throw the error).
| </blockquote>
|
| That's not true. Trailing comma is not explicitly allowed by
| ECMAScript 3 syntax.
|
| <blockquote>
| <code>
| ObjectLiteral :
| {}
| { PropertyNameAndValueList }
|
| PropertyNameAndValueList :
| PropertyName : AssignmentExpression
| PropertyNameAndValueList , PropertyName : AssignmentExpression
| </code>
| </blockquote>
|
| That means you can have {} or { 1 : 2 } or { 1 : 2, 3 : 4 }, but none
| of { , } or {1 : 2, }or { , 3 : 4 }
|
| Trailing comma in object literal is allowed as a syntax extension.
| The production is also valid in ECMAScript Edition 5. You could call |
it a "codification". That fact, and that it works in other browsers,
| are probably the reasons why IE decided to implement it.
|
| You also wrote:
| <blockquote>
| Internet Explorer 8’s JScript engine implements the native JSON
| object object as defined by
| <a href="http://www.ecma-international.org
/publications/standards/Ecma-262.htm">ECMAScript 5</a>. The object is
| only present, however, when the page is running in IE8 document mode.
| This includes the global JSON object as well as methods used for JSON
| functionality:
|
| * Date.prototype.toJSON()
| * Number.prototype.toJSON()
| * String.prototype.toJSON()
| * Boolean.prototype.toJSON()
| </blockquote>
|
| Of that list, only Date.prototype.toJSON is defined. It looks like
| Luke Smith tried to say something to that effect, though I'm not
| quite sure.
|
| I know the spec can be tricky in some places and sometimes not fun to
| read, but those parts should not be too difficult. For example, try
| taking a look at the Boolean.prototype and you'll see
| Boolean.prototype.toString ( ) and Boolean.prototype.valueOf ( ).
| Boolean.prototype doesn't have a toJSON.
|
| http://www.ecma-international.org/publications/standards/Ecma-262.htm

That is what I posted, minus a small typo.

The false information on the blog remains.

Trying to impress less experienced developers with untested statements
is bad, but understandable. Publishing that online and trying to pass
that off as some form of helpful education is worse. Worse yet is
actively ignoring valid criticism. On some level, he must have
recognized that yes, the information posted was factually false.
Censoring the comment should have provided some indication that the
entry was not quite right, but there it remains, unchanged.

I get the sense that Nicholas Zakas lives in a small world of web
developers that are a lot less competent than he is and that he's not
used to being told when he is wrong.

A little social intelligence applied, he would have taken a civil high
road by owning the mistakes. Then again, he may very well have decided
that someone else pointing out a mistake was not considered
"constructive criticism" but "rude" and "off-topic".

Garrett
 
A

Asen Bozhilov

Garrett said:
I decided to leave a comment, but coming back several days later, I
found the comment was not approved. I emailed the author but I got no reply.

Comments there are unwelcome. I have posted too, but unfortunately
Zakas's filter puts my comment in the junk. If you want your comments
to be posted, you should not disproof Zakas posts. That is the
true.

Trying to impress less experienced developers with untested statements
is bad, but understandable. Publishing that online and trying to pass
that off as some form of helpful education is worse. Worse yet is
actively ignoring valid criticism. On some level, he must have
recognized that yes, the information posted was factually false.
Censoring the comment should have provided some indication that the
entry was not quite right, but there it remains, unchanged.

I get the sense that Nicholas Zakas lives in a small world of web
developers that are a lot less competent than he is and that he's not
used to being told when he is wrong.

A little social intelligence applied, he would have taken a civil high
road by owning the mistakes. Then again, he may very well have decided
that someone else pointing out a mistake was not considered
"constructive criticism" but "rude" and "off-topic".

He does not deserve such an attention. He just tries to sell his
books. And he does not give a damn about our criticisms. I remember a
sentence: "The good programmer writes programs, the bad writes books
instead and try to teach other". I am not sure how that is true, but
Zakas a proof that.
However, I do not want to wasting my time with him. I hope someone who
reads Zakas blog/books to read your post here and decide
itself.
 
G

Garrett Smith

Comments there are unwelcome. I have posted too, but unfortunately
Zakas's filter puts my comment in the junk. If you want your comments
to be posted, you should not disproof Zakas posts. That is the
true.

Filtered directly to junk? WTF? You have a lot of knowledge about
ECMAScript and usually make good posts. Sure I've learned a few things
from you.

I've always hated censorship and lying to the public. Trying to pass
that off as education is fraud.

At least I know I'm not the only commenter who was not approved.

Trailing comma in ObjectLiteral has come up here enough times on this
NG. I thought it was odd that nobody had posted a comment regarding
that, but chalked it up to an assumption that he didn't get much
traffic. More likely, somebody already commented about that but the
comment was censored.
He does not deserve such an attention. He just tries to sell his
books. And he does not give a damn about our criticisms. I remember a
sentence: "The good programmer writes programs, the bad writes books
instead and try to teach other". I am not sure how that is true, but
Zakas a proof that.
However, I do not want to wasting my time with him. I hope someone who
reads Zakas blog/books to read your post here and decide
itself.

"You can fool all the people some of the time, and some of the people
all the time, but you cannot fool all the people all the time."

- Abraham Lincoln

I get the sense that Zakas is so used to beling around less experienced
web developers who do not tell him when he is wrong that he's taken that
to be normal and when someone like you or me tries to engage in
technical discussion on an even level, we fall outside his expectations
of what normal behavior is.
If it bothers you as much as it does me, then next time you see
something wrong on that blog --- or any blog -- post a reply. Be
professional and make sure you save a copy of your reply as a file, like
I did. If it doesn't get approved, you can always follow up in email
(don't be rude) and/or twitter/IM, etc. Be patient -- people have lives
and might not get to approving comments right away. If it turns out to
be that the comment was was unapproved, then post it here.

No need to suck up to anybody. If you've stated the facts correctly, the
blog owner should want to approve the comment, so that his blog can be
recognized as a source of good information (regardless who posted that).

The reader wants the truth. Eventually enough people will get the
picture. Zakas gives seminars on javascript development and publishes
books on javascript, so this puts him in the role of teacher. Teacher is
a role that comes with great responsibility.

Garrett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,113
Latest member
XZJMike318

Latest Threads

Top