Semantics of "indexed" string access

Allen Wirfs-Brock Allen.Wirfs-Brock at
Tue Jun 24 18:39:37 PDT 2008

Actually, the intent was to support "indexed" access to both string values and string wrapper objects.  I just didn't make it clear in the example.  The case analysis was intended to apply to both. My reading of section 11.2.1 is that  a string value is to be transformed into an object before any actual property access semantics are applied. Am I wrong?

Is the semantics I described really any different from array indexing?  I actually, borrowed some concepts from Array [[Put]] but it is most about maintaining the length invariant. Other than that I didn't find any array specific property indexing semantics in the ES3 spec.

From: Maciej Stachowiak [mailto:mjs at]
Sent: Tuesday, June 24, 2008 6:21 PM
To: Allen Wirfs-Brock
Cc: es3.x-discuss at; Pratap Lakshman (VJ#SDK); es4-discuss at
Subject: Re: Semantics of "indexed" string access

On Jun 24, 2008, at 5:46 PM, Allen Wirfs-Brock wrote:

I've taken a crack at cleaning up Pratap's initial specification for supporting direct indexing of strings, eg "abc"[1] yields "b"

Here are the semantics that seemed to make sense:

1)  If s has an own property whose name is the same as the value of n, the value of that property is returned.

Since s is a string value, not an object, then it cannot have any own properties. The autogenerated wrapper for s does have some own propertied.

2) else If the value of n is convertible to a number that is within the bounds of the string value, return a string containing the corresponding character
3) else if try to resolve n as the name of an inherited property
4) else return undefined.

In other words, indexing into a string with a "valid" index returns that appropriate character unless somebody has explicitly defined a property named by that index on the object.

It is not possible to define a custom property on a string value. On a string object you could.

I would suggest it makes more sense to make index properties of a string act like index properties of an array, but read-only.


-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Es4-discuss mailing list