News for hackers. Stuff that matters.
Re:React v0.13 released by jbergens on Tuesday March 10, 2015 @07:01PM (#9181370)
The ES6 class system seems to be done to feel more like java and c# without regard for the mixin/prototype parts. I'm glad React still works with mixins. (edit spelling and clarification)
Re:React v0.13 released by stupidcar on Tuesday March 10, 2015 @07:24PM (#9181463)
The ES6 class system is literally just syntactic sugar for prototypal inheritance.
Re:React v0.13 released by TazeTSchnitzel on Tuesday March 10, 2015 @07:53PM (#9181609)
No, it's syntactic sugar for one particular approach to using prototypical inheritance that resembles "traditional" OOP.
Re:React v0.13 released by kendallpark on Wednesday March 11, 2015 @09:52AM (#9184039)
I think one of the biggest irks for me personally when using ES6 is how `this` works.

class Foo { constructor() { this.whatever = 4; }

  bar() {
    this.whatever = 3;
  }
}

var foo = new Foo();

blah.onSomeEvent(foo.bar);

// When SomeEvent is triggered on blah, `this` will refer to blah, not foo.

console.log(blah.whatever); // 3 console.log(foo.whatever); // 4

// You have to: blah.onSomeEvent(foo.bar.bind(foo));

console.log(blah.whatever); // undefined console.log(foo.whatever); // 3

Which I know is just traditional JS, but it's a little unexpected because that's not how most OO languages operate.

Re:React v0.13 released by Touche on Tuesday March 10, 2015 @08:26PM (#9181763)
Can you explain? It's sugar for this very common pattern:

    function Bar() {
      Foo.call(this);
    }

    Bar.prototype = Object.create(Foo.prototype);
    Bar.prototype.constructor = Bar;

    Foo.prototype.thing = function() { ....

What other "approach" to prototypical inheritance is there in JavaScript? The module pattern doesn't use prototypes.
Re:React v0.13 released by jbergens on Wednesday March 11, 2015 @03:13AM (#9182958)
This blog post and presentation discusses this in more detail. http://ericleads.com/2013/02/fluent-javascript-three-differe...
Re:React v0.13 released by backslash_16 on Tuesday March 10, 2015 @10:47PM (#9182254)
Is there a good book or website to learn about prototypical inheritance? I've read a lot of Crockford's book and some stuff online about it, but I've never run across the pattern you use above.

It would be great to know what the benefits are vs declaring function literals on an object, or declaring a function directly on Bar's prototype.

Re:React v0.13 released by cstrahan on Wednesday March 11, 2015 @12:41AM (#9182616)
Mozilla's documentation does a good job explaining prototypal inheritance:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inhe...

Re:React v0.13 released by jurassic on Wednesday March 11, 2015 @01:04AM (#9182667)
My "Aha!" moment came while reading this Kyle Simpson blog series http://davidwalsh.name/javascript-objects
Re:React v0.13 released by bloodyowl on Tuesday March 10, 2015 @08:04PM (#9181648)
no, it's just syntactic sugar
Re:React v0.13 released by s1300045 on Wednesday March 11, 2015 @09:30AM (#9183929)
Which is ultimately what separates a good language from a bad language. A good language should have ONE best way to do things. With the prototypical inheritance, there are impossible numbers of way to declare/define and inherit a class in JavaScript. That is just a trap for bugs and defects. How could you effectively understand what the code does when you can't read it in one glance? Especially code that is not yours.

ES6's class system is infinitely better.

Re:React v0.13 released by aikah on Tuesday March 10, 2015 @09:22PM (#9181965)
no, it introduces a "super" semantic with late binding ,something you can't do in ES5. So it isn't just syntactic sugar. Furthermore it may evolve in later versions of ES to something even more complicated with access modifiers and things like that.
Re:React v0.13 released by __david__ on Wednesday March 11, 2015 @11:30AM (#9184572)
Isn't it just (untested, probably full of errors):

    function super(obj, method) {
        for (var p = obj.prototype; p; p = p.prototype)
            if (p[method])
                return p[method];
        throw method+" not found";
    }
then use:

    subclass.prototype.overridden = function(x,y) {
        super(this, 'some_overriden_method').call(this, x, y);
        // ...
    }
If so, that means it's just sugar. If not, what does it do differently?
Re:React v0.13 released by grandalf on Tuesday March 10, 2015 @08:04PM (#9181647)
If one is not confused by prototypical inheritance, is there any reason to use the ES6 class system?
Re:React v0.13 released by acdlite on Tuesday March 10, 2015 @08:21PM (#9181740)
- More declarative.

- Harder to screw up. Even if you know what you're doing, prototypical inheritance involves several steps which can get repetitive.

- Interoperable with non-es6 "classes". It's not like you're losing anything.

Re:React v0.13 released by jsnoble on Monday March 16, 2015 @12:35PM (#9212445)
Actually it might be easier to screw up. People will think these are real traditional "OO" classes but they are not. Its all prototypal, and you will be in a world of hurt creating bug and performance hits if you treat them as if they are the same. Also, functions inside a ES6 class are hijacked. You cannot bind those functions to work on another context which is a core javascript technique, it will break. Thus in the end, any person familiar with javascript will have to learn even more caveats which will create more confusion. You wouldnt want to use ES6 classes on anything super complex.
Re:React v0.13 released by bloodyowl on Tuesday March 10, 2015 @08:07PM (#9181666)
it reduces the necessary LoC and forces you to only define methods in the [[Proto]] land. ES7 will let you define properties in it, but it will effectively be as if you defined them in the constructor.
Re:React v0.13 released by Touche on Tuesday March 10, 2015 @08:27PM (#9181765)
Yes, it prevents the very common mistake of putting an object on the prototype.