Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. x= {foo:"bar",
  2.     esta: "es"};
  3.  
  4.  
  5. class Robj {
  6.  constructor(o) {
  7.    Object.assign(this, o);
  8.  }
  9.  
  10.  map(fn) {
  11.    return Object.keys(this)
  12.                 .reduce((obj, key) => Object.assign(obj, {[key]: fn(key, this[key], this)}),
  13.                         {});
  14.  }
  15.  filter(fn) {
  16.    return Object.keys(this)
  17.                 .filter( key => {
  18.                   const result = fn(key, this[key], this);
  19.                   return result === false || result === null;
  20.                 })
  21.                 .reduce((obj, key) => Object.assign(obj, {[key]: fn(key, this[key], this)}),
  22.                         {});
  23.  }
  24. }
  25. var y = new Robj(x);
  26.  
  27. z= y.map((key, value) => key + "ASD");
  28.  
  29. console.log(z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement