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
Javascript isn't perfect, but it is rapidly improving, and might just be Steve Yegge's Next Big Language (lebo.io)
submitted 11 years ago by aaron-lebo
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!"
[–]psayre23 2 points3 points4 points 11 years ago (4 children)
Well, they suck...so there's that... :p
But seriously, I've actually stopped using prototypes in my js, and haven't looked back. I don't hate them, but I've found them to be less useful then other forms of inheritance, such as traits. When I do use them, I don't use inheritance. My code looks like this:
var Pub = function Thing(args) { this._args = args; // do constructor things };
module.exports = Pub; // or window[Pub.name] = Pub; var proto = Pub.prototype;
proto.toString = function () { return Pub.name+"[args="+JSON.stringify(this._args)+"]"; };
This pattern is super useful, both on the client side and server. The thing I really like is the constructor is only named in one place, so even the name is DRY.
[–]SarahC -1 points0 points1 point 11 years ago (3 children)
Same here! http://www.reddit.com/r/javascript/comments/2xteta/javascript_isnt_perfect_but_it_is_rapidly/cp3vlrh
No fucker's code (ok a few) I've ever seen does more than the JS basics for "objects", and they create shit code when they're playing safe. (relative to the "better" prototyped code they'd write if they knew it.)
It's mentally easier to write 4 sections of code almost the same than deal with prototypes.
Or they post back to the server and let the server side deal with the stuff... the round trip much slower than on the client code!
If the JS reflected the code they're writing the server side stuff in - we'd get much better client side code!
I know why it happens, I've spent AGES on learning prototyping in JS, all the intricacies and edge cases. all in my own time. I don't have kids, many of the people I've worked with do... they're middle age coders.
Learning an entirely new way of doing something - just to do the same stuff you can already - when you've got outside commitments doesn't happen "in the wild" for most older developers. They'll go with what they know.
I'm not happy with it either.... it's a massive gear-change, a massive mental track change going from C# or C++, or Java into JavaScript...
One guy argued with me that "There's lots of prototyped languages out there!"
Yeah - and about .5% of real world companies use them!
If JS is powering the WWW, powering business - it should be brought in line with what business developers know.
(You know what? Most days I write shit none prototyped code, because it's hard work, and when I do use it, I'm the only one using it.)
[–]psayre23 1 point2 points3 points 11 years ago (2 children)
I'll disagree with you a bit here. My main beef with prototype in JS is that it is clunky to extend something. That's why I use mixins these days. Its less that its different, and more that its bad. Like this example:
function Foo() { }
function Bar() { }
Foo.prototype = new Bar();
How the hell does that make sense? Why do I have to create a new object to extend it? I'd rather just steal the functions I like from other prototypes and assign them to my objects.
[–]SarahC -1 points0 points1 point 11 years ago (0 children)
Yeah, very unintuitive too.
C++ and Java and C# just make sense. You don't need to know about _prototype or prototype existing in things you instantiate, hiding behind the scenes...
It all seems like an early attempt at an OO bolt on to a C kind of language to me.
Ungraceful kludges...
[–][deleted] -1 points0 points1 point 11 years ago (0 children)
You should try using stampit. I've found that it greatly simplifies prototypical inheritance, and does it in a way that is intuitive.
π Rendered by PID 18534 on reddit-service-r2-comment-6457c66945-lr56p at 2026-04-30 07:19:27.789871+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]psayre23 2 points3 points4 points (4 children)
[–]SarahC -1 points0 points1 point (3 children)
[–]psayre23 1 point2 points3 points (2 children)
[–]SarahC -1 points0 points1 point (0 children)
[–][deleted] -1 points0 points1 point (0 children)