Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(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]) { = 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment