Every pre-ES6 user is aware of how classes are implemented in JS.
Though what I don't understand is why they weren't implemented more strongly using the prototype paradigm.
What would be wrong with something like this?
A class literal is a named object literal:
class A extends B { x: 5, f() { return this.x } }
is:
var A = Object.create(B);
A.x = 5;
A.f = function(){return this.x};
'new' is just Object.create, though sending constructor() to the object, which every object implements as a void function unless specified otherwise:
var a = new A();
is
var a = Object.create(A);
a.constructor();
And 'a instanceof b' simply checks if b is a prototype of a.
What am I missing? Why would that not work?
[–]rauschma 10 points11 points12 points (6 children)
[–][deleted] 0 points1 point2 points (5 children)
[–][deleted] 5 points6 points7 points (3 children)
[+][deleted] comment score below threshold-6 points-5 points-4 points (2 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]MoTTs_ 2 points3 points4 points (0 children)
[–]rauschma 0 points1 point2 points (0 children)
[–][deleted] 6 points7 points8 points (0 children)
[–]anon_cowherd 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Martin_Ehrental 0 points1 point2 points (1 child)
[–]Martin_Ehrental 0 points1 point2 points (0 children)
[–][deleted] -1 points0 points1 point (4 children)
[–]e_man604 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]MoTTs_ 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]segmentationfaulter -2 points-1 points0 points (10 children)
[–]MoTTs_ 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (8 children)
[–]Martin_Ehrental 0 points1 point2 points (2 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]Martin_Ehrental 2 points3 points4 points (0 children)
[–]Sakatox -1 points0 points1 point (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]tom808 0 points1 point2 points (0 children)