+ 2
What is differences between method and function..!?
where we can say that this is method or function ..! because almost both are same or both are work as same..as we see that external view of both are same..but how we differentiate it..!? if both are same then why we give naming of both are differentially..!?
4 Antworten
+ 13
in java a function is a method.
+ 1
The difference between them is same as the different between True and not False
0
In javaScript, a method is just a function that belongs to an object.
for example...
var Hotel = {
rooms: 45,
pool: true,
makeBooking: function () {
//make a booking
}
}
Above, Hotel is the object and it has the funtion makeBooking. You would call it like:
Hotel.makeBooking()
Because the makeBooking funtion is belongs to the Hotel object, it is a method.
The following, when written in the global scope is simply a function:
function blah () {
//do stuff
}
You would call this function like:
blah()
Notice that it is NOT called like this:
SomeObject.blah()
Functions that belong to an object are methods.
Functions are just functions.