Last active
February 1, 2019 17:52
-
-
Save letsgetrandy/8ac0339112c1b903d752 to your computer and use it in GitHub Desktop.
Bro, do you even?
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
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