DEV Community

Adam Crockett πŸŒ€
Adam Crockett πŸŒ€

Posted on

JavaScript, stuff you've never heard of (probably): #2 `with` statement

Before I tell you about destructuring's caveman ancestor, the with statement, I would like to make a statement of my own:

β€’ I do not condone or deny the existence of this language feature.
β€’ I fully respect that code in general should be "smarter than table, but dummer than dog". πŸ•
β€’ I am not responsible for any chunks of food left in your keyboard by the close of this post.
β€’ My dog is called Lizzie

Ah yes the with statement, you know the statement, other than this all we need is a that keyword and we have the single most confusing language in history.

with(console) {
    table({legs: 4, material: 'wooood'});
}
Enter fullscreen mode Exit fullscreen mode

The equivalent today is:

const {table} = console;
table({legs: 3, material: 'space wooood'});
Enter fullscreen mode Exit fullscreen mode

The with statement, it's disgusting but I love that it is there, like all unfashionable things, we should never forget, the new things aren't really new, just reimagined.

Thanks for a fantastic response for my last post, didn't expect that!

Top comments (0)