Skip to content

Instantly share code, notes, and snippets.

@letsgetrandy
Last active February 1, 2019 17:52
Show Gist options
  • Save letsgetrandy/8ac0339112c1b903d752 to your computer and use it in GitHub Desktop.
Save letsgetrandy/8ac0339112c1b903d752 to your computer and use it in GitHub Desktop.
Bro, do you even?
if (Object.defineProperty) {
Object.defineProperty(Object.prototype, 'doYouEven', {
value: function(key) {
var props = (key || '').split('.'),
item = this;
for (var i=0; i<props.length; i++) {
item = item[props[i]];
if (typeof item === 'undefined') return false;
}
return true;
},
writable: false,
configurable: false,
enumerable: false
});
var bro = {};
bro.doYouEven('lift'); // returns false
bro.lift = function() { console.log('yo!'); }
bro.doYouEven('lift'); // returns true
bro.foo = { bar: false };
bro.doYouEven('foo.bar'); // returns true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment