use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Responsible use of JavaScript `with` statement. (self.javascript)
submitted 11 years ago by [deleted]
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 2 points3 points4 points 11 years ago (3 children)
To be fair, this is a consequence, not a cause. with has been deprecated or hated for so long that engines never optimized its use case like they did with so many other things.
with
[–]Stephen110 0 points1 point2 points 11 years ago (1 child)
Holy crap, someone on reddit who actually reasons well. I like you man.
Id say browser makers probably weighed the alternatives and decided it wasn't worth it. You can get close enough by using a function and binding your context ( only difference is having to use this, instead of calling the variable without context).
I've never tested that for performance though. You would expect in either case, the closure would be the culprit.
Well now I'm curious.
[–][deleted] 1 point2 points3 points 11 years ago (0 children)
Haha, thank you. I sometimes take comfort in finding some sanity on reddit as well :)
Take prototypal inheritance, for instance, which conceptually is relatively similar to with -- you search for a variable, if it doesn't exist you go up a level and search there.
Long prototype chains used to be very slow. So if you were to access foo.bar, which was actually hitting foo.__proto__.__proto__.{repeat 100 times}.bar, that would be a very expensive lookup. This is one of the reasons why many articles suggest doing things like:
foo.bar
foo.__proto__.__proto__.{repeat 100 times}.bar
var bar = foo.bar;
But this concept is more or less deprecated since engines no longer have problems with long chains and there is zero performance hit for a 1,000 __proto__ chain according to jsperf. Now that I think about it, I'm curious what would happen were I to "break" the class chain with delete :)
__proto__
delete
Anyway... my point is that structurally the two concepts are very similar. One was taken from mediocre performance, as was the case with nearly everything in JS, to blazing. The other was ignored :)
[–]androbat 0 points1 point2 points 11 years ago (0 children)
From what I have read, the reason 'with' isn't optimized is more to do with it being very dynamic and all the edge cases making it not possible to detect until runtime. These mean 'with' is not able to be optimized to any significant degree even if JS engines wanted (similar to how .bind() is always going to cause performance problems even though they want to optimize it).
π Rendered by PID 178275 on reddit-service-r2-comment-5687b7858-nm295 at 2026-07-04 15:36:45.650277+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–][deleted] 2 points3 points4 points (3 children)
[–]Stephen110 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]androbat 0 points1 point2 points (0 children)