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 Object-Oriented JavaScript (2015) Constructor Functions and Prototypes Creating Multiple Instances with Constructors

What is the difference between function chaining and method chaining?

Do we use the term "function chaining" when the functions we are chaining have been created OUTSIDE and object? or are they synonym terms?

2 Answers

You've pretty much got it - a method is a member function of an object. Within an object, primitive values or other objects are properties, and functions are methods.

The term "function chaining" isn't one I'm familiar with, and doesn't make intuitive sense with how functions work in Javascript. Chaining is done on object instances using methods (hence "method chaining") that are available to that object. Of course methods are created using functions, however a regular function cannot be chained because dot notation is not available. Method chaining is really just a convenience, but is only available when a method returns this (the current object). This blog post does a good job of explaining method chaining (something you'll use a lot with jQuery): https://schier.co/blog/2013/11/14/method-chaining-in-javascript.html

This is correct, as far as I know - I kind of focused on the difference between a function and a method, but the question is about chaining. Function chaining isn't a thing as far as I'm aware - the whole point of method chaining is that it's all done on the same item, hence "method".