tight vs loose coupling (js)

ref – https://www.reddit.com/r/learnjavascript/comments/30mnra/tight_vs_loose_coupling_examples/

In JS, tight coupling between methods and objects in which if you were to change property name to say naaaaame,
then method sayName will not work.

Change from tight to loose

There is a tight coupling with Food and Fork. Because Fork was instantiated inside nomNomNom, you are forced to use a Fork for every Food.

Let’s correct it by using a parameter object to pass in whatever tool we need to use. This way, we inject whatever tool we need into the eating function.

The only thing we need to make sure is that the tool has a getType function and conforms to a common interface. That way, we can get the name of the tool.