archives

« Bugzilla Issues Index

#2370 — Notes for `Function#call` and `Function#apply` are confusing


https://bugzilla.mozilla.org/show_bug.cgi?id=948407
https://bugs.webkit.org/show_bug.cgi?id=125501
https://code.google.com/p/v8/issues/detail?id=3052

From http://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.call
& http://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.apply:

> The `thisArg` value is passed without modification as the `this` value. This is
> a change from Edition 3, where a `undefined` or `null` `thisArg` is replaced with
> the global object and `ToObject` is applied to all other values and that result is
> passed as the `this` value.

What is not mentioned in this note is that this only applies to strict mode code. Paragraph
11 of ES 5.1’s Annex C (http://ecma-international.org/ecma-262/5.1/#sec-C) clarifies this:

> If `this` is evaluated within strict mode code, then the `this` value is not coerced
> to an object. A `this` value of `null` or `undefined` is not converted to the global
> object and primitive values are not converted to wrapper objects. The `this` value
> passed via a function call (including calls made using `Function.prototype.apply` and
> `Function.prototype.call`) do not coerce the passed `this` value to an object (10.4.3,
> 11.1.1, 15.3.4.3, 15.3.4.4).

Suggested fix: just prepend “in strict mode code, […]” to each of these two notes.


> Suggested fix: just prepend “in strict mode code, […]” to each of these two notes.

The notes may be confusing, but are correct nonetheless. Whereas just adding "In strict mode code" makes them incorrect, since built-in functions like Function.prototype.{apply, call} have no notion of strict mode at all.
There are two choices here:
(1) Either remove the notes because they were only useful during the transition from ES3 -> ES5
(2) Or if strict mode needs to be mentioned, then use a more thorough description. Like:

> Even though `thisArg` is passed without modification, non-strict mode functions still replace the `thisArg` with the global object and apply `ToObject`, cf. 9.2.1 [[Call]] (thisArgument, argumentsList).


> There are two choices here:
> (1) Either remove the notes because they were only useful during the transition
> from ES3 -> ES5
> (2) Or if strict mode needs to be mentioned, then use a more thorough
> description. Like:
>
> > Even though `thisArg` is passed without modification, non-strict mode functions still replace the `thisArg` with the global object and apply `ToObject`, cf. 9.2.1 [[Call]] (thisArgument, argumentsList).

Option 2 definitely gets my vote — would make things much clearer, at no significant cost.


fixed in rev23 editor's draft

using a variation of choice 2


fixed in rev23 draft