Created
January 7, 2015 21:51
-
-
Save fearphage/eb439159c7adfc327acd to your computer and use it in GitHub Desktop.
Python's defaultdict
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 defaultDict(constructor) { | |
return new Proxy({}, { | |
get: function(object, property) { | |
return property in object | |
? object[property] | |
: object[property] = constructor() | |
; | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment