Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. Object.defineProperty(Object.prototype, 'deepVal', {
  2. enumerable: false,
  3. configurable: false,
  4. writable: false,
  5. value: function (string){
  6. var props = string.split("."),
  7. val = {};
  8. for(var key in this){
  9. val[key] = this[key];
  10. }
  11. for(var i = 0,len = props.length;i<len;i++){
  12. val = val[props[i]];
  13. }
  14. return val;
  15. }
  16. });
  17.  
  18. var a = {
  19. "b" : {
  20. "c" : "d"
  21. }
  22. };
  23. console.log(a.deepVal("b.c")); // d
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement