I spoke with the ECMA-262 standard (ECMAScript Language Specification, 3rd edition, if that matters), I did not find the difference between the 3rd and 5th edition of String Type / String Object).
There is one thing that puzzles me: the difference between a string type and a string object. Yes, I know the difference in the sense that the String Type is a sequence of 16-bit UTF-16 units, and the String Object is an inline object with its internal Class property set to "String" and its internal value Value, value of type String.
But reading the spec, the string type does not seem to expose any methods; that is, it is simply a value without any additional properties. Take this code, everything is exactly as expected:
document.writeln(typeof "foo"); // 'string' document.writeln(typeof new String("foo")); // 'object'
The first type is the actual type of the string, and the second is the type of the object (this is an object of class String, but its data type is an object). However, looking at this:
"foo".charAt(0); fooStrObj = new String("Foo"); fooStrObj.charAt(0);
Both of them seem to reveal the same functions, but there are no functions in the string type defined in the ECMA-262 standard; all the functions it provides are related to the String.prototype object (and I donβt see a reference to the fact that String Type magically exposes all the properties and functions of the String.prototype object in the ECMA-262 standard). Similarly, String Type values ββare automatically passed to the String object with the original String value as its internal property Value?
And if they are processed in exactly the same way (which for all goals and tasks they seem to be), why are there two different ways of representing a string?
javascript
thr Jan 12 '10 at 19:43 2010-01-12 19:43
source share