Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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".