Why are they termed differently?
Isn't the nature/purpose/place of a function identical to that of a method?
Why are they termed differently?
Isn't the nature/purpose/place of a function identical to that of a method?
A method is a function that is attached to an object.
JavaScript functions are usually referred to as methods when used in the context of an object.
e.g. document.getElementById('foo') uses the getElementById method.
Function is a very old term meaning a segment of code that accomplishes some task (does some function, if you will).
Method is a relatively newer term (came with OO programming) that means a function that belongs to a specific instance of an object.
All methods are functions, but not all functions are methods.
See this related question from the programmers stackexchange.
thisA function is a piece of code that is called by name. It can be passed data to operate on (ie. the parameters) and can optionally return data (the return value).
All data that is passed to a function is explicitly passed.
A method is a piece of code that is called by name that is associated with an object. In most respects it is identical to a function except for two key differences.
Also, another answer: Difference between function and method?
arguments object, this isn't explicitly passed. Besides: closures don't really pass arguments, but the scopes are linked to the function all the same. JavaScript and C# are like boats and cars, they both move, have engines etc... but their based on different concepts.Well, its all about the names, but generally functions and methods are the same thing, and of course have the same purpose.
It all began with the first programming languages, where they where called functions, but as more higher level programming languages arose, i guess they thought to name them methods even if they are and serve the sasme purpose.
EDIT:
Functions are not part of any object or class. Methods are a memeber of an object or class.