When you read a book about a web technology that is constantly changing, expect that some or all of the information will be out-of-date.
In ES5 there was no name
property defined for function instances, nor was it defined for Function.prototype
.
In ES2015, the name
property was defined for function instances:
The value of the name property is an String that is descriptive of the function. The name has no semantic significance but is typically a variable or property name that is used to refer to the function at its point of definition in ECMAScript code. This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.
Anonymous functions objects that do not have a contextual name associated with them by this specification do not have a name own property but inherit the name property of %FunctionPrototype%.
it was also defined for function.prototype
:
The value of the name property of the Function prototype object is the empty String.
There's also an algorithm defined called SetFunctionName
, which appears to handle assigning a name
property in a variety of cases, such as when a function is used as part of an object literal.
This is as far down the rabbit hole as I've dug. I would not be surprised if Chrome and Firefox had different levels of support for the SetFunctionName
or if there were differences between the ES2015 and ES2017 specs that would lead to the behavior you're seeing.