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