Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Treehouse Club - MASH MASH - JavaScript The Structure of Functions

Sølvi Qorda
Sølvi Qorda
14,194 Points

Difference between a method and a function?

Hi,

I was wondering if anyone could describe the difference between a method and a function. Joy talks here about a function being something that you can repeat over and over again. In Java, that seems to be what methods do to...is that just different syntax for a similar thing?

Thanks in advance.

4 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi Solvi.

is that just different syntax for a similar thing?

Pretty much. method is just function, plain and simple, and sometimes programmers may call them procedure or subroutine as well.

In the Object Oriented Programming paradigm, you may often come across the terms such as class method and instance method, they are just functions bond to a class or an object.

Jason Berteotti
Jason Berteotti
12,352 Points

Methods are effectively functions within an object. There is essentially no difference other than the obvious, such as the method being passed as part of the object, being able to use "this" on the object's data, and scope related differences. In regards to JavaScript, methods can be created and spread through prototypical inheritance so that you can make your code more DRY, since each instance of your object will inherit the method you wrote once.

Sølvi Qorda
Sølvi Qorda
14,194 Points

Thank you both, really helpful explanations :)

Armand van Alphen
Armand van Alphen
16,969 Points

The make it MISS "make it stupid simple"

--> A method is a function <--

**details can be read inside the other posts.