1 comment

[ 3.0 ms ] story [ 11.5 ms ] thread

  Object.prototype.get = function(k, d){
    return k.split(".").reduce(function(a, b){
      return a ? b in a && a[b] || d : a 
    }, this)
  };

  // ({}).get('a.b.c', null) === null
  // ({a:{b:{c:2}}}).get('a.b.c') === 2