+ 9
I am confuse between function and method, how can differ between them?
11 Answers
+ 21
A function is a statement that can be called when you type the word you used to define it as, A method is when you use any function as a value tied to a specific property inside of an object. All methods are also functions (just used in at least one object) but not all functions are methods (because you can create a function and never use it with an object)
+ 8
functions are independent. They can operate outside class like in C++ or C. Methods by definition will exist and operate only within classes.
+ 3
For the most part it's computer scientist trying to sound smart. If you confuse the two, no harm done. In Javascript:
var bankaccount = {
'withdraw' : function(){ ... }
};
We say `withdraw` is a function, but it is also a method of `bankaccount`. In other words, methods are functions belonging to objects.
+ 3
first of all a method is a function but all function are not method by default . The difference rely on the way you call them and declare them .For our traditional function their declaration and call is very simple and all of us know how to do it..With method the particularity is that you can declare it inside an object only or class and their call is through instance of that class..
+ 1
it's the same but we usually call functions methods for objects
+ 1
understand it lyk this..-
methods are functions of objects only.!!
and functions are just like functions in C ir C++
+ 1
It's semantics and has to do with what you are trying to express.
In javascript every function is an object. An object is a collection of key:value pairs. If a value is a primitive (integer, string, boolean), or another object, the value is considered a property. If a value is a function, it is called a 'method'.
Within the scope of an object, a function is referred to as a method of that object. It is invoked from the object namespace 'MyObj.theMethod()'. Since we said a function is an object, a function within a function is considered a method of that function. You can say I am going to use the save method of my object. Or you could say, "the save method accepts a function as a parameter". But you generally wouldn't say a function accepts a method as a parameter.
+ 1
Method: are usually in classes.
Functions: Have independent existence.
0
an object it's a representation of "something" in real world, e.g a Person it's an object, and "walk" a method
0
very simple To comprehend .think object as container of named variable .When this variable is a function it is called a method
- 4
can you help me?