Given someFunc
, is it a function, a method, or a constructor? Honestly, the answer is N/A. A function in JavaScript could be any of those depending on how it’s invoked.
// invoked as a function
someFunc();
// invoked as a constructor
new someFunc();
// invoked as a method
someObject.someFunc();
// invoked as a method?
someFunc.call(someObject);
In all these cases, the only difference is what the value of this
will be during that particular invocation. When invoked as a function, this
will be the global object (or undefined if in strict mode). When invoked as a constructor, this
will be a brand new object. When invoked as a method, this
will be the object on which the method was invoked. And when invoked with call or apply, this
is set manually.
So what is Date? Depends on each invocation.