+ 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..!?

3rd Oct 2017, 4:51 PM
Vishal Sakariya
Vishal Sakariya - avatar
4 Respostas
+ 13
in java a function is a method.
3rd Oct 2017, 5:11 PM
D_Stark
D_Stark - avatar
+ 1
The difference between them is same as the different between True and not False
3rd Oct 2017, 5:23 PM
Kartikey Sahu
Kartikey Sahu - avatar
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.
4th Oct 2017, 1:54 PM
Daniel Prodrick
Daniel Prodrick - avatar