var a = <c>1</c>; alert(a); works in firefox, why?

O

opok

a turns out as 1. But ie, safari will throw exception.

I want to check whether a string is a valid json, obviousely the
string "<c>1</c>" is not a json, but when i eval("<c>1</c>") in
firefox, it passed and turned out as 1.
 
G

Garrett Smith

opok said:
a turns out as 1. But ie, safari will throw exception.

I want to check whether a string is a valid json, obviousely the
string "<c>1</c>" is not a json, but when i eval("<c>1</c>") in
firefox, it passed and turned out as 1.

Type conversion of |c| to a string probably let you to the conclusion
that: it was 1.

alert(<c>1</c>)

elerts "1" in Firefox.

There are many built-in and native host methods that will convert an
argument to a string. The alert method, for example:-

This is E4X[1], which is implemented in Spidermonkey[2].

10.1.1 ToString Applied to the XML Type:-

| Given an XML object x, the operator ToString converts x to a string s.
| If a value of type XML has simple content (i.e., contains no
| elements), it represents a primitive value and ToString returns the
| String contents of the XML object, omitting the start tag, attributes,
| namespace declarations and end tag. Otherwise, ToString returns a
| string representing the entire XML object, including the start tag,
| attributes, namespace declarations and the end tag. NOTE the actual
| format of the resulting string content is implementation defined.

try:-

alert(typeof <c>1</c>)

A compliant implementation should result in "xml".

Garrett

[1]http://www.ecma-international.org/publications/standards/Ecma-357.htm
[2]https://developer.mozilla.org/en/E4X
 

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,102
Messages
2,570,646
Members
47,253
Latest member
AntwanNews

Latest Threads

Top