How can I create a list of functions in JavaScript that preform actions together like this?
I’m sorry I don’t know what it called but something like Jquery when you select something than you add class to it and also you can do something else in the same time!
For Example:
list.getAll().count()
Or
list.getAll().removeLast().dosomthingElse().count()
I tried many ways but unfortunately I can’t get it working unless I extend the Function Class which is not what i want!
That’s called chaining methods. You simply return the object reference (
this) from the method:Or if the method produces a new result, you create an object of the same type and return that:
(You could also create an object of a different type. For example a
toCollectionmethod could create a newCollectionobject with all the items from the list and return that.)