LoginSignup
0
1

More than 5 years have passed since last update.

2019年の書き初め。Proxyを使って2019を🐗🐗🐗🐗に書き換える

Posted at

あけましておめでとうございます。
書き初めがてらProxyを使って、配列の値が2019のものだけ🐗🐗🐗🐗に書き換える、実に他愛もないコードを書いてみました。

MDN - Proxy
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Proxy

const rewriteToBoar = {
  set(obj, prop, value) {
    if (value === "2019") {
      obj[prop] = "🐗🐗🐗🐗";
      return true;
    } else {
      obj[prop] = value;
      return true;
    }
  }
};

const years = new Proxy([], rewriteToBoar);
years.push("2017");
years.push("2018");
years.push("2019");
years.push("2020");
console.log(years); // => [ '2017', '2018', '🐗🐗🐗🐗', '2020' ]

今年もよろしくお願いします。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1