Unless you override Function.prototype.call and Function.prototype.apply (and pass another argument to your function), there is no way to do this - the actual internal mechanics (the internal [[Call]] function) provides no way to signal that it is being called using () .
Compare the specification of calling common functions with Function.prototype.apply - each call to the internal function code is done in exactly the same way, and there is no external set of properties that can give you a call using this or not.
See the specification of the internal function [[Call]] :
13.2.1 [[Call]]
When the internal [[Call]] method for an object of function F is called with this value and a list of arguments, the following steps are performed:
- Let funcCtx be the result of creating a new execution context for the function code using the value of the internal property F [[FormalParameters]], the arguments passed to List args and this value, as described in 10.4.3.
- Let the result be the result of evaluating FunctionBody, which is the value of the internal property F [[Code]]. If F does not have an internal [[Code]] property or if its value is empty FunctionBody, the result will be (regular, undefined, empty).
- Close the funcCtx execution context by 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 should be normal. Return undefined.
There is no need to change the operation of the function from whether it is called using call / apply or not - the only thing that changes what it does is the arguments for the function itself and that this should be inside the function.
Qantas 94 Heavy
source share