![](http://habrastorage.org/getpro/habr/avatars/e88/c8c/eba/e88c8ceba87b95e6a4c987506c1e3ecc.png)
Bare words in JavaScript
Once relaxing on the couch, I remembered a fleeting wonderful movie from my childhood, which was called WAT . And there was such a thing as bare words, which was shown on the example of Ruby.
![image](https://habrastorage.org/getpro/habr/post_images/93a/d55/e3a/93ad55e3ac2060373db1d13f385dc684.jpg)
Bare words are words without quotes that you can use as strings.
In JavaScript, they seem to be absent, so I tried to push them into it, which in general turned out.
The result is this code:
And it was implemented like this:
As you can see, so that we can use bare words, we used such features of the javascript as Proxy and with .
When trying to get a property from this, due to the intrigues with, the request goes to the proxy, where we return a string value instead of a vicious error about the absence of a variable.
Thanks for attention.
![image](https://habrastorage.org/getpro/habr/post_images/582/748/934/5827489348907e77e83a0c831d42aec3.png)
If anything, here's a link to Github
![image](https://habrastorage.org/getpro/habr/post_images/93a/d55/e3a/93ad55e3ac2060373db1d13f385dc684.jpg)
Bare words are words without quotes that you can use as strings.
In JavaScript, they seem to be absent, so I tried to push them into it, which in general turned out.
The result is this code:
with(bareWords) {
alert(Иван + Ургант)
console.log(We, can, use, bare, words)
}
And he successfully displayed the necessary phrases. And it was implemented like this:
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('Your browser doesn\'t support bare words.')
}
As you can see, so that we can use bare words, we used such features of the javascript as Proxy and with .
When trying to get a property from this, due to the intrigues with, the request goes to the proxy, where we return a string value instead of a vicious error about the absence of a variable.
Thanks for attention.
![image](https://habrastorage.org/getpro/habr/post_images/582/748/934/5827489348907e77e83a0c831d42aec3.png)
If anything, here's a link to Github