LoginSignup
0

More than 5 years have passed since last update.

Javascriptのbare words

Posted at

昔ソファーで休んで子供の時の面白い映画を覚えた。名前はWATだ。rubyの例でbare wordsのことが初めて見つけた。
obaa chaan omae wa mou shindeiru
でもJavaScriptでそんなことが無くてJavaScriptにそんなことを入れた。

コードはこちら
with(bareWords) {
    console.log(お前, , もう, 死んでいる)
    alert()
}

コードは全部の言葉を見せる

理由は
try {
    let self = this
    window.bareWords = new Proxy({}, {
        has: function(target, name) {
            return !(name in self)
        },
        get: function(target, name) {
            return name
        },
    })
} catch(e) {
    console.error('お前は生きている')
}

見るようにProxyとwithを使えてbare wordsのことができた。
https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Proxy
https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/with
oie_zKkzfJCTTjcD.png

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