Created
December 19, 2008 23:17
-
-
Save visnup/38168 to your computer and use it in GitHub Desktop.
dynamic js object literals
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
// 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