Created
November 22, 2011 12:59
-
-
Save wsoczynski/1385611 to your computer and use it in GitHub Desktop.
The no framework JS framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment