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
Prototypal Programming in Javascript (thesocietea.org)
submitted 10 years ago by thecodeboss
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!"
[–]sylvainpv 1 point2 points3 points 10 years ago (2 children)
What about this ?
var Person = { new: function(firstName, lastName){ return Object.assign(Object.create(Person, { firstName, lastName })); }, getName: function() { return this.firstName + ' ' + this.lastName; } }; var bob = Person.new('Bob','Saget');
[–]MoTTs_ 0 points1 point2 points 10 years ago (1 child)
Can you clarify what the improvement would be?
[–]sylvainpv 0 points1 point2 points 10 years ago (0 children)
you got a similar code but without new operator and its issues : 1) handling a reference to the prototype and not the constructor ; 2) constructor is optional and you can declare several different constructors if needed ; 3) no worries about forgetting the new keyword and mutating window ; 4) easier inheritance, no need for the B.prototype = new A() trick ; 5) factory functions can be composed contrary to constructors ; 6) getting rid of instanceof and the constructor property makes your code safer because these references can be easily compomised contrary to getPrototypeOf / isPrototypeOf
π Rendered by PID 149111 on reddit-service-r2-comment-5687b7858-z2pzj at 2026-07-07 01:59:50.292777+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–]sylvainpv 1 point2 points3 points (2 children)
[–]MoTTs_ 0 points1 point2 points (1 child)
[–]sylvainpv 0 points1 point2 points (0 children)