Skip to content

Instantly share code, notes, and snippets.

@wsoczynski
Created November 22, 2011 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wsoczynski/1385611 to your computer and use it in GitHub Desktop.
Save wsoczynski/1385611 to your computer and use it in GitHub Desktop.
The no framework JS framework
//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