B.2 Additional Built-in Properties

When the ECMAScript host is a web browser the following additional properties of the standard built-in objects are defined.

B.2.1 Additional Properties of the Global Object

The entries in Table 82 are added to Table 8.

Table 82: Additional Well-known Intrinsic Objects
Intrinsic Name Global Name ECMAScript Language Association
%escape% escape The escape function (B.2.1.1)
%unescape% unescape The unescape function (B.2.1.2)

B.2.1.1 escape ( string )

The escape function is a property of the global object. It computes a new version of a String value in which certain code units have been replaced by a hexadecimal escape sequence.

For those code units being replaced whose value is 0x00FF or less, a two-digit escape sequence of the form %xx is used. For those characters being replaced whose code unit value is greater than 0x00FF, a four-digit escape sequence of the form %uxxxx is used.

The escape function is the %escape% intrinsic object. When the escape function is called with one argument string, the following steps are taken:

  1. Set string to ? ToString(string).
  2. Let length be the number of code units in string.
  3. Let R be the empty String.
  4. Let k be 0.
  5. Repeat, while k < length,
    1. Let char be the code unit (represented as a 16-bit unsigned integer) at index k within string.
    2. If char is one of the code units in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./", then
      1. Let S be the String value containing the single code unit char.
    3. Else if char ≥ 256, then
      1. Let n be the numeric value of char.
      2. Let S be the string-concatenation of:
        • "%u"
        • the String representation of n, formatted as a four-digit uppercase hexadecimal number, padded to the left with zeroes if necessary
    4. Else,
      1. Assert: char < 256.
      2. Let n be the numeric value of char.
      3. Let S be the string-concatenation of:
        • "%"
        • the String representation of n, formatted as a two-digit uppercase hexadecimal number, padded to the left with a zero if necessary
    5. Set R to the string-concatenation of R and S.
    6. Set k to k + 1.
  6. Return R.
Note

The encoding is partly based on the encoding described in RFC 1738, but the entire encoding specified in this standard is described above without regard to the contents of RFC 1738. This encoding does not reflect changes to RFC 1738 made by RFC 3986.

B.2.1.2 unescape ( string )

The unescape function is a property of the global object. It computes a new version of a String value in which each escape sequence of the sort that might be introduced by the escape function is replaced with the code unit that it represents.

The unescape function is the %unescape% intrinsic object. When the unescape function is called with one argument string, the following steps are taken:

  1. Set string to ? ToString(string).
  2. Let length be the number of code units in string.
  3. Let R be the empty String.
  4. Let k be 0.
  5. Repeat, while klength,
    1. Let c be the code unit at index k within string.
    2. If c is the code unit 0x0025 (PERCENT SIGN), then
      1. Let hexEscape be the empty String.
      2. Let skip be 0.
      3. If klength - 6 and the code unit at index k + 1 within string is the code unit 0x0075 (LATIN SMALL LETTER U), then
        1. Set hexEscape to the substring of string from k + 2 to k + 6.
        2. Set skip to 5.
      4. Else if klength - 3, then
        1. Set hexEscape to the substring of string from k + 1 to k + 3.
        2. Set skip to 2.
      5. If hexEscape can be interpreted as an expansion of HexDigits[~Sep], then
        1. Let hexIntegerLiteral be the string-concatenation of "0x" and hexEscape.
        2. Let n be ! ToNumber(hexIntegerLiteral).
        3. Set c to the code unit whose value is (n).
        4. Set k to k + skip.
    3. Set R to the string-concatenation of R and c.
    4. Set k to k + 1.
  6. Return R.

B.2.2 Additional Properties of the Object.prototype Object

B.2.2.1 Object.prototype.__proto__

Object.prototype.__proto__ is an accessor property with attributes { [[Enumerable]]: false, [[Configurable]]: true }. The [[Get]] and [[Set]] attributes are defined as follows:

B.2.2.1.1 get Object.prototype.__proto__

The value of the [[Get]] attribute is a built-in function that requires no arguments. It performs the following steps when called:

  1. Let O be ? ToObject(this value).
  2. Return ? O.[[GetPrototypeOf]]().

B.2.2.1.2 set Object.prototype.__proto__

The value of the [[Set]] attribute is a built-in function that takes an argument proto. It performs the following steps when called:

  1. Let O be ? RequireObjectCoercible(this value).
  2. If Type(proto) is neither Object nor Null, return undefined.
  3. If Type(O) is not Object, return undefined.
  4. Let status be ? O.[[SetPrototypeOf]](proto).
  5. If status is false, throw a TypeError exception.
  6. Return undefined.

B.2.2.2 Object.prototype.__defineGetter__ ( P, getter )

When the __defineGetter__ method is called with arguments P and getter, the following steps are taken:

  1. Let O be ? ToObject(this value).
  2. If IsCallable(getter) is false, throw a TypeError exception.
  3. Let desc be PropertyDescriptor { [[Get]]: getter, [[Enumerable]]: true, [[Configurable]]: true }.
  4. Let key be ? ToPropertyKey(P).
  5. Perform ? DefinePropertyOrThrow(O, key, desc).
  6. Return undefined.

B.2.2.3 Object.prototype.__defineSetter__ ( P, setter )

When the __defineSetter__ method is called with arguments P and setter, the following steps are taken:

  1. Let O be ? ToObject(this value).
  2. If IsCallable(setter) is false, throw a TypeError exception.
  3. Let desc be PropertyDescriptor { [[Set]]: setter, [[Enumerable]]: true, [[Configurable]]: true }.
  4. Let key be ? ToPropertyKey(P).
  5. Perform ? DefinePropertyOrThrow(O, key, desc).
  6. Return undefined.

B.2.2.4 Object.prototype.__lookupGetter__ ( P )

When the __lookupGetter__ method is called with argument P, the following steps are taken:

  1. Let O be ? ToObject(this value).
  2. Let key be ? ToPropertyKey(P).
  3. Repeat,
    1. Let desc be ? O.[[GetOwnProperty]](key).
    2. If desc is not undefined, then
      1. If IsAccessorDescriptor(desc) is true, return desc.[[Get]].
      2. Return undefined.
    3. Set O to ? O.[[GetPrototypeOf]]().
    4. If O is null, return undefined.

B.2.2.5 Object.prototype.__lookupSetter__ ( P )

When the __lookupSetter__ method is called with argument P, the following steps are taken:

  1. Let O be ? ToObject(this value).
  2. Let key be ? ToPropertyKey(P).
  3. Repeat,
    1. Let desc be ? O.[[GetOwnProperty]](key).
    2. If desc is not undefined, then
      1. If IsAccessorDescriptor(desc) is true, return desc.[[Set]].
      2. Return undefined.
    3. Set O to ? O.[[GetPrototypeOf]]().
    4. If O is null, return undefined.

B.2.3 Additional Properties of the String.prototype Object

B.2.3.1 String.prototype.substr ( start, length )

The substr method takes two arguments, start and length, and returns a substring of the result of converting the this value to a String, starting from index start and running for length code units (or through the end of the String if length is undefined). If start is negative, it is treated as sourceLength + start where sourceLength is the length of the String. The result is a String value, not a String object. The following steps are taken:

  1. Let O be ? RequireObjectCoercible(this value).
  2. Let S be ? ToString(O).
  3. Let size be the length of S.
  4. Let intStart be ? ToIntegerOrInfinity(start).
  5. If intStart is -∞, set intStart to 0.
  6. Else if intStart < 0, set intStart to max(size + intStart, 0).
  7. If length is undefined, let intLength be size; otherwise let intLength be ? ToIntegerOrInfinity(length).
  8. If intStart is +∞, intLength ≤ 0, or intLength is +∞, return the empty String.
  9. Let intEnd be min(intStart + intLength, size).
  10. If intStartintEnd, return the empty String.
  11. Return the substring of S from intStart to intEnd.
Note

The substr function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method.

B.2.3.2 String.prototype.anchor ( name )

When the anchor method is called with argument name, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "a", "name", name).

B.2.3.2.1 CreateHTML ( string, tag, attribute, value )

The abstract operation CreateHTML takes arguments string, tag (a String), attribute (a String), and value. It performs the following steps when called:

  1. Let str be ? RequireObjectCoercible(string).
  2. Let S be ? ToString(str).
  3. Let p1 be the string-concatenation of "<" and tag.
  4. If attribute is not the empty String, then
    1. Let V be ? ToString(value).
    2. Let escapedV be the String value that is the same as V except that each occurrence of the code unit 0x0022 (QUOTATION MARK) in V has been replaced with the six code unit sequence "&quot;".
    3. Set p1 to the string-concatenation of:
      • p1
      • the code unit 0x0020 (SPACE)
      • attribute
      • the code unit 0x003D (EQUALS SIGN)
      • the code unit 0x0022 (QUOTATION MARK)
      • escapedV
      • the code unit 0x0022 (QUOTATION MARK)
  5. Let p2 be the string-concatenation of p1 and ">".
  6. Let p3 be the string-concatenation of p2 and S.
  7. Let p4 be the string-concatenation of p3, "</", tag, and ">".
  8. Return p4.

B.2.3.3 String.prototype.big ( )

When the big method is called with no arguments, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "big", "", "").

B.2.3.4 String.prototype.blink ( )

When the blink method is called with no arguments, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "blink", "", "").

B.2.3.5 String.prototype.bold ( )

When the bold method is called with no arguments, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "b", "", "").

B.2.3.6 String.prototype.fixed ( )

When the fixed method is called with no arguments, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "tt", "", "").

B.2.3.7 String.prototype.fontcolor ( color )

When the fontcolor method is called with argument color, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "font", "color", color).

B.2.3.8 String.prototype.fontsize ( size )

When the fontsize method is called with argument size, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "font", "size", size).

B.2.3.9 String.prototype.italics ( )

When the italics method is called with no arguments, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "i", "", "").

B.2.3.10 String.prototype.link ( url )

When the link method is called with argument url, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "a", "href", url).

B.2.3.11 String.prototype.small ( )

When the small method is called with no arguments, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "small", "", "").

B.2.3.12 String.prototype.strike ( )

When the strike method is called with no arguments, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "strike", "", "").

B.2.3.13 String.prototype.sub ( )

When the sub method is called with no arguments, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "sub", "", "").

B.2.3.14 String.prototype.sup ( )

When the sup method is called with no arguments, the following steps are taken:

  1. Let S be the this value.
  2. Return ? CreateHTML(S, "sup", "", "").

B.2.3.15 String.prototype.trimLeft ( )

Note

The property "trimStart" is preferred. The "trimLeft" property is provided principally for compatibility with old code. It is recommended that the "trimStart" property be used in new ECMAScript code.

The initial value of the "trimLeft" property is the same function object as the initial value of the String.prototype.trimStart property.

B.2.3.16 String.prototype.trimRight ( )

Note

The property "trimEnd" is preferred. The "trimRight" property is provided principally for compatibility with old code. It is recommended that the "trimEnd" property be used in new ECMAScript code.

The initial value of the "trimRight" property is the same function object as the initial value of the String.prototype.trimEnd property.

B.2.4 Additional Properties of the Date.prototype Object

B.2.4.1 Date.prototype.getYear ( )

Note

The getFullYear method is preferred for nearly all purposes, because it avoids the “year 2000 problem.”

When the getYear method is called with no arguments, the following steps are taken:

  1. Let t be ? thisTimeValue(this value).
  2. If t is NaN, return NaN.
  3. Return YearFromTime(LocalTime(t)) - 1900𝔽.

B.2.4.2 Date.prototype.setYear ( year )

Note

The setFullYear method is preferred for nearly all purposes, because it avoids the “year 2000 problem.”

When the setYear method is called with one argument year, the following steps are taken:

  1. Let t be ? thisTimeValue(this value).
  2. If t is NaN, set t to +0𝔽; otherwise, set t to LocalTime(t).
  3. Let y be ? ToNumber(year).
  4. If y is NaN, then
    1. Set the [[DateValue]] internal slot of this Date object to NaN.
    2. Return NaN.
  5. Let yi be ! ToIntegerOrInfinity(y).
  6. If 0 ≤ yi ≤ 99, let yyyy be 1900𝔽 + 𝔽(yi).
  7. Else, let yyyy be y.
  8. Let d be MakeDay(yyyy, MonthFromTime(t), DateFromTime(t)).
  9. Let date be UTC(MakeDate(d, TimeWithinDay(t))).
  10. Set the [[DateValue]] internal slot of this Date object to TimeClip(date).
  11. Return the value of the [[DateValue]] internal slot of this Date object.

B.2.4.3 Date.prototype.toGMTString ( )

Note

The toUTCString method is preferred. The toGMTString method is provided principally for compatibility with old code.

The function object that is the initial value of Date.prototype.toGMTString is the same function object that is the initial value of Date.prototype.toUTCString.

B.2.5 Additional Properties of the RegExp.prototype Object

B.2.5.1 RegExp.prototype.compile ( pattern, flags )

When the compile method is called with arguments pattern and flags, the following steps are taken:

  1. Let O be the this value.
  2. Perform ? RequireInternalSlot(O, [[RegExpMatcher]]).
  3. If Type(pattern) is Object and pattern has a [[RegExpMatcher]] internal slot, then
    1. If flags is not undefined, throw a TypeError exception.
    2. Let P be pattern.[[OriginalSource]].
    3. Let F be pattern.[[OriginalFlags]].
  4. Else,
    1. Let P be pattern.
    2. Let F be flags.
  5. Return ? RegExpInitialize(O, P, F).
Note

The compile method completely reinitializes the this value RegExp with a new pattern and flags. An implementation may interpret use of this method as an assertion that the resulting RegExp object will be used multiple times and hence is a candidate for extra optimization.