Reputation: 145
I am confused. Every function that is ever called in Javascript is called by some object. If I invoke it like this: b();
then this means that my global object invoked it: global.b();
. So, all of them are methods, right? Why do we call them functions then?
Upvotes: 0
Views: 71
Reputation: 6665
Because a method is a function.
Function definition:
A "subroutine" that returns a value
Method definiton:
A callable member of a object
=> A function of a object
So you could say:
class Method extends Function
In Javascript every function returns a value, if it doesn't it returns undefined. Which makes it return something.
But the real answer is: Does it even matter? I'm going to cite the resource from the software engineering stack: "The point is, none of this is really consistent. It simply reflects the terminology employed by whatever languages are en vogue at the time."
Resources: https://softwareengineering.stackexchange.com/a/20948/258140
Upvotes: 2