Created
October 28, 2010 11:07
-
-
Save adamsilver/651117 to your computer and use it in GitHub Desktop.
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
var A = function() {} | |
var B = function() {} | |
// factory | |
var Type = function(name) { | |
if(name === "a") { | |
return new A(); | |
} | |
else { | |
return new B(); | |
} | |
} | |
// example of using the above factory | |
// dummy data to show example | |
var myArray = ["a", "a", "b", "c", "b", "a"]; | |
// loop through array | |
for(var i = 0; i < myArray.length; i++) { | |
// will create a new A or B depending on what the factory decides | |
new Type(myArray[i]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment