I need help in understanding that algorithm:
[[Call]]
When the [[Call]] internal method for a Function object F is called with a this value and a list of arguments, the following steps are taken:
- Let funcCtx be the result of establishing a new execution context for function code using the value of F's [[FormalParameters]] internal property, the passed arguments List args, and the this value as described in 10.4.3.
- Let result be the result of evaluating the FunctionBody that is the value of F's [[Code]] internal property. If F does not have a [[Code]] internal property or if its value is an empty FunctionBody, then result is (normal, undefined, empty).
- Exit the execution context funcCtx, restoring the previous execution context.
- If result.type is throw then throw result.value.
- If result.type is return then return result.value.
- Otherwise result.type must be normal. Return undefined.
https://www.ecma-international.org/ecma-262/5.1/#sec-13.2.1
Exactly I need in explanation in 2,4,5,6 clauses.
About 2: First, what does the result of the FunctionBody calculation mean? How is it calculated? What does it mean there is no [[Code]] property when this happens? And most importantly, what does this record mean (normal, undefined, empty).
About 4,5,6: What does result.type mean, result.value? Where does this value come from? Explain for each point
P.S If you vote down, explain why you do that!
First, the [[Call]] is propabily about Function.prototype.call()
, so it's better to understand call()
first because it's easier than algorithm.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
I get this sample code from the MDN, and try to answer the question roughly. (If you want to understand in detail, you and I have to understand the whole specification, but I don't!)
function greet() {
var reply = [this.person, 'Is An Awesome', this.role].join(' ');
console.log(reply);
}
var obj = {
person: 'Douglas Crockford', role: 'Javascript Developer'
};
greet.call(obj); // Douglas Crockford Is An Awesome Javascript Developer
First, what does the result of the FunctionBody calculation mean?
FunctionBody is function's code. From the sample, FunctionBody is below.
var reply = [this.person, 'Is An Awesome', this.role].join(' ');
console.log(reply);
the result of the FunctionBody calculation
is the result of the code execution. The result is expressed by Completion Specification Type(explain below). It includes the function return
value, but has more wider information.
What does it mean there is no [[Code]] property when this happens?
It's mean empty function as below.
function greet() {
// empty
}
And most importantly, what does this record mean (normal, undefined, empty).
It's Completion Specification Type. This is an expression for value or statement in specification. Values of the Completion type are triples of the form (type, value, target).
What does result.type mean, result.value? Where does this value come from? Explain for each point
result is Completion Specification Type, and the form is (type, value, target).