Skip to content

Instantly share code, notes, and snippets.

@visnup
Created December 19, 2008 23:17
Show Gist options
  • Save visnup/38168 to your computer and use it in GitHub Desktop.
Save visnup/38168 to your computer and use it in GitHub Desktop.
dynamic js object literals
// a helper function to create more dynamic object literals
// $h('key'+i, value) => { key1: value }
var $h = function() {
var constructor = function() {
var k = null, args = arguments[0];
for (var i = 0; i < args.length; i++) {
if (k == null) {
k = args[i];
} else {
this[k] = args[i];
k = null;
}
}
};
return new constructor(arguments);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment