//persons module persons = (function(){ //private Person object constructor var Person = function(firstName, lastName, birthDate){ var foo = "bar"; var name = function(){ return firstName + " " + lastName; } var age = function(){ var currentYear = (new Date()).getYear() var birthDayYear = birthDate.getYear() return currentYear - birthDayYear } var saySomething = function(){ return foo; } //the methods that will be public return { "name": name, "age": age, "saySomething": saySomething } } //private FitnessAddict object constructor var FitnessAddict = function(firstName, lastName, birthDate, weight, height){ var person = Person(firstName, lastName, birthDate); var bmi = function(){ return weight / (height*height); } var isWeightNormal = function(){ var currentBmi = bmi() if(currentBmi > 25){ return false } if(currentBmi < 18.5){ return false } return true } //we make isWeightNormal method public person.isWeightNormal = isWeightNormal; return person; } //we make the fitnessAddict object constructor public return { "fitnessAddict": FitnessAddict } })()