Last active
August 29, 2015 14:14
-
-
Save pdtaylor/435da0afbe8ffba4ca09 to your computer and use it in GitHub Desktop.
Example 1
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
(function(){ //opens the closure | |
//definition of private object Animal | |
var Animal= function(){ | |
this.name=""; | |
}; | |
Animal.prototype={ | |
getAnimal : function(code){ | |
if(code=="c"){ | |
this.name="Cat"; | |
} | |
else if(code=="d"){ | |
this.name="Dog"; | |
} | |
else{ | |
this.name="unknown"; | |
} | |
} | |
}; | |
//myLib public interface | |
window.myLib = { | |
selectAnimal : function(code){ | |
var selector=new Animal(); | |
selector.getAnimal(code); | |
return selector.name; | |
} | |
}; | |
})(); //closes the closure | |
//Call selectAnimal publicly | |
window.myLib.selectAnimal(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment