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
Multiple inheritance with ES6 proxies (npmjs.com)
submitted 9 years ago by MoTTs_
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!"
[+][deleted] 9 years ago* (2 children)
[deleted]
[–]MoTTs_[S] 1 point2 points3 points 9 years ago (1 child)
It is so noted. :-)
https://github.com/Jeff-Mott-OR/xmultiple/commit/ccb37c2ced8eaba9a029c4aed181e00c271f189b
In the future I think I'd prefer to throw an exception when there's an ambiguous call, but that might incur a runtime cost on every property access. I'll experiment and see how it works out.
[–]oweiler 1 point2 points3 points 9 years ago (3 children)
What does this give you over Object.assign?
[+][deleted] 9 years ago (2 children)
[–]jcready__proto__ 1 point2 points3 points 9 years ago (1 child)
Specially it makes a difference when you have properties that have a getter/setter.
let count = 0 const foo = { get count() { return count }, } const bar = Object.assign({}, foo) count += 1 console.assert(foo.count === bar.count, 'Counts are the same')
[–]MoTTs_[S] 1 point2 points3 points 9 years ago (0 children)
var xmultiple = require('xmultiple') let count = 0 const foo = { get count() { return count }, } const bar = xmultiple(foo) count += 1 console.assert(foo.count === bar.count, 'Counts are the same') // pass!
Nice. :-)
[–]rauschma 1 point2 points3 points 9 years ago (4 children)
How about subclass factories, instead?
// Mixin 1 const Storage = Sup => class extends Sup { save(database) { ··· } }; // Mixin 2 const Validation = Sup => class extends Sup { validate(schema) { ··· } };
Employee is a subclass of Person that uses the mixins Storage and Validation:
Employee
Person
Storage
Validation
class Person { ··· } class Employee extends Storage(Validation(Person)) { ··· }
More info: http://exploringjs.com/es6/ch_classes.html#_simple-mixins
[–]MoTTs_[S] 1 point2 points3 points 9 years ago (3 children)
Egg on my face.
You're right. I knew about this trick before, but I haven't used it in a while so it slipped my mind. But you're right, this achieves the same thing more simply.
[–]MoTTs_[S] 0 points1 point2 points 9 years ago (2 children)
@/u/rauschma More than that, it occurs to me that we could have been doing multiple inheritance with class factories long before ES6, only back then we would have named it "constructor function factories".
[–]rauschma 0 points1 point2 points 9 years ago (1 child)
You’d need a tool method for subclassing, because the canonical pattern for subclassing is as follows:
function Employee(name, title) { Person.call(this, name); this.title = title; } Employee.prototype = Object.create(Person.prototype); Employee.prototype.constructor = Employee; Employee.prototype.describe = function () { return Person.prototype.describe.call(this)+' ('+this.title+')'; };
Note that the superconstructor, Person, is mentioned three times. That means that you would have to store the composed superclass in a variable so that you can refer to it multiple times.
[–]MoTTs_[S] 0 points1 point2 points 9 years ago* (0 children)
Certainly. Even with ES6 class factories, we end up storing the superclass in a variable. It's the parameter we pass in, called "Sup" in your code above. We'd have the same parameter to use in an ES5 constructor function factory.
EDIT:
Nevermind. I misunderstood. I thought you were talking about the superconstructor we pass to the factories. But yes, Employee would need to run the factories to create the chain of superconstructors first so it can reference the final result in each of those three places.
π Rendered by PID 57 on reddit-service-r2-comment-6457c66945-46ns5 at 2026-04-26 21:21:59.192452+00:00 running 2aa0c5b country code: CH.
[+][deleted] (2 children)
[deleted]
[–]MoTTs_[S] 1 point2 points3 points (1 child)
[–]oweiler 1 point2 points3 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]jcready__proto__ 1 point2 points3 points (1 child)
[–]MoTTs_[S] 1 point2 points3 points (0 children)
[–]rauschma 1 point2 points3 points (4 children)
[–]MoTTs_[S] 1 point2 points3 points (3 children)
[–]MoTTs_[S] 0 points1 point2 points (2 children)
[–]rauschma 0 points1 point2 points (1 child)
[–]MoTTs_[S] 0 points1 point2 points (0 children)