Tightcoupling what ???

Tight coupling (in general) is when two things depends on one another, that is, changing one may have impact on another.

In JavaScript, method and object is said to be tightly coupled. Suppose you change person.name to person.naame, the method sayName() will break, so are other methods that access name using this way.

One way to slightly loose the coupling is to provide a getter method getName() and use it instead of referencing the instance variable directly. Hence if you want to change person.name to something else, you just need to change this method.



Tight
coupling using the above explanation would be like this:


var person = {
name: "Jack",
sayName: function() {
alert(person.name);
}
};     







Comments

Popular posts from this blog

JavaScript — Double Equals vs. Triple Equals - weird things on JavaScript

06_Understanding Execution Context and Execution Stack in Javascript

Creating and inserting element- part-2