Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Created September 25, 2010 21:25
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 robotlolita/597318 to your computer and use it in GitHub Desktop.
Save robotlolita/597318 to your computer and use it in GitHub Desktop.
(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