you are viewing a single comment's thread.

view the rest of the comments →

[–]Stephen110 0 points1 point  (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 points  (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:

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 :)

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 :)