Ryan Zygg
Ryan Zygg

Reputation: 341

Chaining in Javascript

could you please explain me this piece of code? Thank you.

items.addItem("a").addItem("b").addItem("c").run();

Upvotes: 0

Views: 113

Answers (2)

enobrev
enobrev

Reputation: 22532

Not sure what framework you're using, but the addItem method returns the parent instance (return this), so you can call another method upon the output.

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798606

It's an example of a fluent interface.

Upvotes: 1

Related Questions