Created
September 25, 2010 21:25
-
-
Save robotlolita/597318 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
(function() { /* creates a new scope */ | |
var created = {}; // all objects that have been created. | |
function create(name, value) { | |
/* this is within the main function's scope, so we have access to all | |
variables defined in it from here */ | |
var obj = {}; | |
if (!created[name]) { | |
obj.data = value; | |
created[name] = obj; | |
} | |
} | |
create('foo', 'bar'); // creates `foo` | |
create('bar', 'baz'); // creates `bar` | |
create('foo', 'baz'); // doesn't create `foo` because it has already been | |
// created. | |
console.log(created); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment