A function is a piece of code that is called by name. It can be passed data to operate on (i.e. 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 a name that is associated with an object. In most respects it is identical to a function except for two key differences:
- A method is implicitly passed the object on which it was called.
- A method is able to operate on data that is contained within the class (remembering that an object is an instance of a class – the class is the definition, the object is an instance of that data).
(this is a simplified explanation, ignoring issues of scope etc.)
Related Posts:
- “Parameter” vs “Argument”
- Inheritance vs. Aggregation [closed]
- What is dependency injection?
- What does ‘super’ do in Python? – difference between super().__init__() and explicit superclass __init__()
- What is Inversion of Control?
- What is ADT? (Abstract Data Type)
- What is an example of the Liskov Substitution Principle?
- What __init__ and self do in Python?
- When should you use a class vs a struct in C++?
- C++ error ‘Undefined reference to Class::Function()’ [duplicate]
- How do I implement interfaces in python?
- What is polymorphism, what is it for, and how is it used?
- java – invalid method declaration; return type required [duplicate]
- java – invalid method declaration; return type required
- Is C++ an Object Oriented language?
- Difference between abstraction and encapsulation?
- What are metaclasses in Python?
- What is the difference between a framework and a library?
- extends class and implements interface in java
- What is a “driver class”?
- What is difference between functional and imperative programming languages?
- How can I create a copy of an object in Python?
- Prefer composition over inheritance?
- What is polymorphism in Javascript?
- When should I be using classes in Python?
- includes() not working in all browsers
- How to return a boolean method in java?
- How to create a subclass in C#?
- How would one write object-oriented code in C?
- How to get a JavaScript object’s class?
- What is a coroutine?
- Parameter name omitted error?
- What is the difference between an Instance and an Object?
- What does ‘low in coupling and high in cohesion’ mean
- What is an example of the Single Responsibility Principle?
- Will WordPress become completely OOP?
- How to name files of namespaced classes?
- What is the best way to instantiate a class of a plugin in your WordPress theme?
- problem with implementing widget via the_content()
- Load classes using spl_autoload_register
- UML diagrams of WordPress
- Trying to get property of non-object
- Static vs Dynamic methods in WordPress
- Autoloader not finding classes from my plugin
- Integration tests test script enqueue/register fails
- Error of “Call a member function on non object” while var_dump get correct result
- How pass args to wp_list_comments callback?
- Does &$this is really disallowed to use anywhere?
- Don’t filters violate the a class’ local variables visibility rules?
- Admin submenu does not call function to load the page
- Using Geo Data Store Plugin Code
- How to wait for WordPress Core to load when writing OOP?
- OOP – from plugin add new object and call static method in another file
- How to get parameters with add_filter with a static method?
- What is an ORM, how does it work, and how should I use one? [closed]
- Converting bytes to megabytes
- What is an idempotent operation?
- What is the purpose of the word ‘self’?
- What and where are the stack and heap?
- What is tail recursion?
- What is a race condition?
- What’s the difference between passing by reference vs. passing by value?
- What is a callback function?
- What is a loop invariant?
- Understanding Python super() with __init__() methods [duplicate]
- What is a loop invariant?
- Is Java “pass-by-reference” or “pass-by-value”?
- What is reflection and why is it useful?
- Define a global variable in a JavaScript function
- How to send an email with Python?
- What is the maximum number of weekdays in a year? How would you code it?
- C++ — expected primary-expression before ‘ ‘
- What is boilerplate code?
- strdup() – what does it do in C?
- strdup() – what does it do in C?
- What exactly is the difference between “pass by reference” in C and in C++?
- Is Java “pass-by-reference” or “pass-by-value”?
- Define a global variable in a JavaScript function
- What do < and > stand for?
- Cannot read property ‘addEventListener’ of null
- IOException: The process cannot access the file ‘file path’ because it is being used by another process
- Return array in a function
- What is JSONP, and why was it created?
- What is a “method” in Python?
- Meaning of = delete after function declaration
- Difference between Inheritance and Composition
- How do I define a function with optional arguments?
- What is the proper declaration of main in C++?
- What is the difference between private and protected members of C++ classes?
- What does it mean if a Python object is “subscriptable” or not?
- Basic explanation of python functions
- ‘foo’ was not declared in this scope c++
- What is Bit Masking?
- What are bitwise shift (bit-shift) operators and how do they work?
- What is the naming convention in Python for variable and function names?
- What is the difference between a deep copy and a shallow copy?
- What does it mean if a Python object is “subscriptable” or not?
- What is the difference between tree depth and height?
- How to create a jQuery function (a new jQuery method or plugin)?
- What is the meaning of the term “thread-safe”?