Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object.defineProperty(Object.prototype, 'deepVal', {
- enumerable: false,
- configurable: false,
- writable: false,
- value: function (string){
- var props = string.split("."),
- val = {};
- for(var key in this){
- val[key] = this[key];
- }
- for(var i = 0,len = props.length;i<len;i++){
- val = val[props[i]];
- }
- return val;
- }
- });
- var a = {
- "b" : {
- "c" : "d"
- }
- };
- console.log(a.deepVal("b.c")); // d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement