-
-
Save Thermatix/2b49a80ed90168ef98317ea5179df6e9 to your computer and use it in GitHub Desktop.
Equivalent to Ruby hash fetch in Javascript
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
Object.prototype.fetch = function (key, value,callback) { | |
return this.hasOwnProperty(key) ? this[key] : (value ? value : (callback ? callback.call : (function () { | |
throw new Error('key not found') | |
})())); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment