This forum is now read-only. Please use our new forums! Go to forums
Why are "functions" inside objects called "methods"?
In every method exercise so far, methods are explained as “like functions” or “similar to functions”, since they even use the same keyword and syntax. The only difference I have gathered is that they are used inside an object, while functions are not. Is this really the only reason for calling them “methods”?
I’d find it more helpful to just call them “functions inside objects”, since that’s more descriptive expression.
Answer 5052ffd8d618140002039158
It’s just traditional terminology that has been around for many years in object-oriented programming. You could equally ask why children that are attending school are called students instead of just children. The term method bears more information, because you know immediately that there’s some object that this method belongs to (and if the object is obj
, you have to call that method using dot notation obj.methodName()
), while you can call other functions without prepending an object and a dot to them.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency