Skip to content

Instantly share code, notes, and snippets.

@vpalos vpalos/get-field.js
Last active Dec 16, 2015

What would you like to do?
Universal field getter for JavaScript objects.
* Universal field getter method for JavaScript objects.
* @param {Object} _path The field path inside `this`.
* @param {...} _default The default value to be returns if field is not found.
* @return {...} Returns the found field value else `_default` else `undefined`.
Object.prototype._ = Object.prototype._ || function(_path, _default) {
var value = _path.split('.').reduce(
function(hash, field) {
return hash && hash[field]
return typeof(value) === 'undefined' ? _default : value;

This comment has been minimized.

Copy link

commented Apr 19, 2013

Long comment:

FWIW: Posting comments on your personal blog returns 403. ☺

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.