https://github.com/getify/You-Dont-Know-JS/tree/master/this%...
192 karma · joined April 23, 2013
[ my public key: https://keybase.io/getify; my proof: https://keybase.io/getify/sigs/SxqB6BQX2LQ92yiAfs1FYql_tPEhCqCGAZhnkap6tVY ]
https://github.com/getify/You-Dont-Know-JS/tree/master/this%...
https://gist.github.com/getify/9895188
For a bit more "real world" of a scenario, you can also compare the `LoginController` / `AuthController` mechanism here, first shown with inheritance+composition, and then shown with simpler OLOO-style delegation:
https://github.com/getify/You-Dont-Know-JS/blob/master/this%...
I have been writing about exactly this topic, of why classes don't make sense (specifically for JS), in my second title of the "You Don't Know JS" book series, "this & Object Prototypes".
In particular, Chapter 6 makes the case for an alternate pattern to class-orientation design, which I call OLOO (objects-linked-to-other-objects) style code. OLOO implements the "behavior delegation" design pattern, and embraces simply peer objects linked together, instead of the awkwardness of parent-child abstract class semantics.
https://github.com/getify/You-Dont-Know-JS/blob/master/this%...
http://thenextweb.com/insider/2013/07/23/akamai-average-inte...
My 80% number was hyperbole, but I do think the data supports that on world-wide average, mobile connections are drastically lower, and so making assumptions about a file size downloading quickly on fast broadband is ignoring an increasingly important part of the web traffic, which are years behind wired connections in terms of speeds.
Or on like better than 80% of all mobile data connections in the world. But mobile is so niche, right? No need to worry about them.
Really? 93kb of code is lightweight? Yeah I know it gzips smaller, but that's still not what I'd call "ligthweight". It's not bloated, but it's certainly not a micro-lib.
> you might on the next
I think this might miss the point. If you're just writing code on sites, sure, consider jQuery. But if you're creating a library or framework that thousands of others may use, your decision to pick jQuery is making that choice for THEM, which means you should think about it a lot more closely.
It's not then about whether you might like it "next time", but whether the people using your lib/framework will likely need jQuery. That decision should not be made glibly or lightly.
Especially if you're only using a small portion of that 93kb of jQuery, and could just "do it yourself".
I use all kinds of public OSS'd libraries and tools. I just don't use frameworks that prescribe an exact way those should be glued together, nor do I stick my own opinions about how the glue should work out "there" to try and convince others they should do it exactly like I do.
Ironically, the site I vaguely referred to in the post WAS actually fully open-sourced. But NOT so that people could look at that code and say "Ah, he's saying that I should always do that same thing with every site I build".
You said "almost entirely wrong". What did I get right?
What I don't use, nor do I try to force on others, is the best ways to glue these pieces together. I have my ideas of "best practices", but those ideas are highly adjustable per site/app, and also just my own opinions. No piece I bring into a project makes an intrusive assumption about how the rest of my code will work.
I love the assumptions that because I write any amount of glue code, the code I write must certainly be less tested and therefore less quality than that which shows up in a popular framework.
But...
> You know what I did? I wrote a framework for that site, and I called it “the site”.
The key differences between my "framework" and these popular frameworks:
1. I'm not holding out my "framework" for that specific site as some general reusable "best practice" for every other site on the planet.
2. It's highly customized, and customizable, to the specific site. When I don't like how events interact with views, I don't need to worry about forking some general framework project (and creating upstream update nightmares) and hacking into the guts of it to change the assumptions it makes. My "framework" is much thinner of abstraction, and far less convoluted.
Not because my "framework" is better. Just because my "framework" is specific to the task.
What I don't do is make intrusive assumptions about the entirety of your application's architecture simply because you include my one little focused tool.
And, btw, it's not private. Most of my code is on github. I just don't try to force it down others' throats.
TL;DR: Everything you need to know about if I'm a good fit is available online in my OSS (et al) track-records. If that's not good enough for you, that's not the kind of job I want anyway. I want to work for companies that value the full lifecycle of OSS work, which you can only see in such a way, and CANNOT judge via tech interviews.
By the time I walk in the door for an in-person interview, I expect you to already know that I am fully qualified (tech and otherwise), and you're looking now to judge my cultural fit by sitting me down in a real team meeting and seeing how it works, etc.
If I show up and you try to quiz my tech skills, you didn't do your homework on me, and I have no more time for you, so I'll just chuckle and walk out. Politely of course.
* Part 1: JS Objects: Inherited a Mess [1]
* Part 2: JS Objects: Distractions [2]
* Part 3: JS Objects: De"construct"ion [3]
[1] http://davidwalsh.name/javascript-objects[2] http://davidwalsh.name/javascript-objects-distractions
[3] http://davidwalsh.name/javascript-objects-deconstruction
AIUI, functions were not originally first-class citizens. My understanding is (and I may very well be incorrect), in these very early days, functions not being objects precluded an awful lot of what we currently "know" to be true about how JS emulates "classes" with function.prototype. I tried to find good citations for this fact, but I'm having trouble finding good "early JavaScript" history.
I do know that at least as early as ES1, in mid-1997, we had constructors with prototypes and "new". [1]
In any case, besides `Object.create()` which you've noted, here are some other milestones in the evolution of "OO in JS" I could find:
`instanceof` was added in JavaScript 1.4 [2], which was sometime after Oct 1998 [3], probably officially in ES3.
`Object#isPrototypeOf()` was added in ES3 [4], which was around late 1999.
`Object.getPrototypeOf()` was added in ES5 [5], which was around 2009.
[1] http://www.ecma-international.org/publications/files/ECMA-ST...
[2] https://developer.mozilla.org/en-US/docs/JavaScript/Referenc...
[3] http://en.wikipedia.org/wiki/Javascript#Version_history
[4] https://developer.mozilla.org/en-US/docs/JavaScript/Referenc...
[5] https://developer.mozilla.org/en-US/docs/JavaScript/Referenc...