A new function name property proposal

Brandon Benvie brandon at brandonbenvie.com
Thu Nov 15 19:03:06 PST 2012

This is based on

Justification: the usefulness of the name of function is not just for
debugging. It is useful in the same ways that property names as strings are
such as dispatching by name or assigning by name.

The goals expand a bit beyond the ones in the strawman, and are also
updated based on the current state of affairs. The first goal is that every
function has an own "name" property, and this property is always a string
(unless the user specifically decides to violate this norm), and that this
name property is initialized with the value that makes sense from static
semantics.The third goal is to allow predefined names to be altered in
cases where it makes sense.


The baseline for every function is the 'name' property defined as
{ value: "",
  writable: true,
  enumerable: false,
  configurable: false }.

For FunctionDeclarations, named FunctionExpressions, MethodDefinitions, or
accessor Properties then the function's "name" property is set to the given
identifier. In the case of the constructor method of classes, the class
name is used instead. In the case of accessors, 'get ' or 'set ' is
included. The "name" property is set to non-writable. Function.prototype's
name is also non-writable.

Anonymous FunctionExpressions and ArrowFunctionExpressions assigned in a
VariableDeclaration or ObjectExpression are given the name of the variable
or property they are assigned to and the name remains writable. Anonymous
ClassExpressions follow the same semantics, with the name being used for
the constructor method.

Whenever a function's name is defined by a Symbol instead of a regular
identifier then the name is the result of ToString(symbol).

The name property should (probably) not have any reflection on the output
of Function.prototype.toString.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121115/ad6ef4b6/attachment-0001.html>

More information about the es-discuss mailing list