Example
function anInstanceOfFunction(data) { this.data = data; } thisArgument = {"data" : null}; // all instances of Function(function definitions or dynamical functions by `new Function`) has // their [[prototype]] chained to the Function constructor's prototype property(Function.prototype) anInstanceOfFunction.call(thisArgument, "dat"); console.log(thisArgument.data);
Function.prototype.call ( thisArgument, argumentsList )
note Function.prototype itself is a function object(to ensure compatibility with es2015), which returns undefined when called; but the call here is `Function.prototype.` instead of `Function.prototype(`
- If IsCallable(F) is false, throw a TypeError exception.//F is anInstanceOfFunction in our example
- Pop from the execution context stack//the top execution context has no further use and optimized out
- Let calleeContext be PrepareForOrdinaryCall(F, undefined):
calleeContext = { "Function" : F, "LexicalEnvironment" : new NewFunctionEnvironment(F), } calleeContext.VariableEnvironment = calleeContext.LexicalEnvironment Push calleeContext onto the execution context stack return calleeContext
- calleeContext.LexicalEnvironment.EnvironmentRecord.[[ThisValue]] = thisArgument
- Let result be Evaluate F with argumentsList.
- Remove(exactly, Pop) calleeContext from the execution context stack
- If result.[[Type]] is return, return NormalCompletion(result.[[Value]]).
- ReturnIfAbrupt(result).
- Return NormalCompletion(undefined).
No comments:
Post a Comment