Alex Sexton
alexsexton.com · Personal blog · on HN since 2010
Alex Sexton is a front-end developer who writes on JavaScript, web performance, deployment, and productivity.
What HN saysOne commenter calls his inheritance post the best intro to how JavaScript inheritance really works; HN also links his Monty Hall Rewrite and a small Uglify GUI.
19HN people shared it
6linked it in comments
14stories submitted
191story points
2 years agolast shared
2010people per year2026
Most-shared posts
- 1Understanding JavaScript Inheritance5 people · 10 points · first shared 2013 · discussion on HN
- 2The Monty Hall Rewrite3 people · 13 points · first shared 2014 · discussion on HN
- 3The 15 Commandments of Front-End Performance2 people · 7 points · first shared 2015 · discussion on HN
- 4The Productivity Cycle1 people · 143 points · first shared 2014 · 38 comments on HN
- 5Deploying JavaScript Applications1 people · 11 points · first shared 2013 · discussion on HN
- 6The UX of Language1 people · 3 points · first shared 2012 · 1 comments on HN
- 7JavaScript Goto Statement1 people · 2 points · first shared 2022 · discussion on HN
- 8Introducing The Jed Toolkit1 people · 1 points · first shared 2012 · discussion on HN
- 9My Thoughts on AMD1 people · 1 points · first shared 2012 · discussion on HN
- 10Post 1061 people · first shared 2011
- 11Demo1 people · first shared 2010
- 12Thirdparty1 people · first shared 2011
- 13Uglifui1 people · first shared 2011
What HN people wrote when they linked it
tristan_juricek · 2014-03-31
This approach to discussing inheritance treats JavaScript as if you're a Java or C++ programmer, and completely lacks any clarity with how inheritance in JavaScript really works.
Best intro I've read on the topic I'm talking about is from Alex Sexton (just read the last example, it really hits the nail on the head):
https://alexsexton.com/blog/2013/04/understanding-javascript-inheritan…
So you might want a wee bit of hierarchy, if you're thinking like those "shared options" scenario, but not in the "OO type abstraction tree".
So, you might have something like a "Account.prototype.primeInterestRate" property that you can change in a running program, and then all the other types of account can calculate interest based on that shared property.
However, the more experienced jS developers I've met might take those "Account.prototype.balance" and "Account.prototype.deposit" methods, and push those into a "mixin" type (like "CurrentBalance") where those methods are copied (not inherited) onto the child class prototype, and those methods, might have initializer helpers to set up the "currentBalance" property they use. This mixin approach only gets gnarly if there's any feature envy. (Document your object properties clearly, folks. This is where javaScript's flexibility often becomes a crutch - lots of issues happen if mixin code uses "this.foo" for different things.)
Anyhow, what's interesting here is that Account carries the property that's shared, but CurrentBalance…
rmurphey3 · 2011-03-03
I think this post is neither trolling nor calling on people to blindly switch to Dojo. It is pointing out a thing I see over and over and over again: people choosing jQuery for tasks to which it is simply not suited. Yes, if you know what you're doing you can make it work -- Alex Sexton makes this argument quite well in his post "On 'Rolling Your Own' Large jQuery Apps" (http://alexsexton.com/?p=106).
This post asks developers who blindly choose jQuery, based on its popularity and an often-misguided sense of self-assuredness, a straightforward question:
"Tell me how, exactly, you plan to solve these problems you haven't even thought about yet? If you proceed blindly with jQuery, then by the time you think about them, you will be effed. So, maybe you ought to ponder, for a solitary moment, that there might be things you haven't thought about yet, and consider a toolkit that's thought about JavaScript app development questions for years, rather than a library whose competencies are still and painfully limited to DOM, Ajax, events and effects."
I applaud the people who answer this question competently with jQuery as a base. What I take issue with is the people who aren't willing to consider for a second that, for all its popularity and simplicity, jQuery might not be the right tool for every JavaScript job under the sun.
cratermoon · 2025-03-09
AKA The Monty Hall Rewrite https://alexsexton.com/blog/2014/11/the-monty-hall-rewrite
IgorPartola · 2011-10-21
You can do cross-domain POSTs. You just cannot get a response from the server. Often times though you can get the length of the response. This can be used to do a POST to change settings on an unsecured Wi-Fi routers, for example and checking whether the call succeeded or not by the length of the response.
The method described in the SO answer is similar, from what I can tell, to what DISQUS uses. I believe they call it JSONPI: http://alexsexton.com/thirdparty/#forms-are-cool-too
paulirish · 2011-04-01
Here's an ugly GUI for Uglify: http://alexsexton.com/uglifui/
bgriggs1 · 2010-12-13
Here's a useful comparative demo that makes this a little easier to differentiate:
http://alexsexton.com/inheritance/demo/