When the toString
method is called with an object func as its thisValue, the following steps are taken:
toString
Representation Requirements:
If func was defined using ECMAScript code,
eval
in a lexical context that is equivalent to the lexical context used to create func, an object will be created such that the object's [[Call]] internal method is indistinguishable from the [[Call]] internal method of func. Two [[Call]] internal methods are indistinguishable if, for all thisArgument
values, argumentList
values, and current execution context stack context
, each method returns the same value according to SameValue and has the same effects on context
when invoked with thisArgument
and argumentList
in the execution context context
. The string representation must not mention freely any variables that were not mentioned freely by func's source code, even if these "extra" names were originally in scope. NOTE: This rule can be widened to include MethodDefinition and GeneratorMethod by saying the [[Call]] behaviour would be the same if the function does not contain (according to the Contains static semantic rule) this
, new.target
, or super
.Else, if func has an [[ECMAScriptCode]] internal slot, the string representation must have the syntax of a FunctionExpression. NOTE Functions created using the Function constructor are not defined using ECMAScript code, but do have an [[ECMAScriptCode]] internal slot.
Else, the string representation must have the syntax of a NativeFunction.
NativeFunction : function BindingIdentifieropt ( FormalParameters ) { [ native code ] }