top | item 3264873 Improving EcmaScript5 OO with sugar 16 points| Raynos | 14 years ago |raynos.org | reply 12 comments order hn newest [+] [-] raganwald|14 years ago|reply “There are multiple similar prototypical OO utilies... All solve the same problem:”http://xkcd.com/927/ [+] [-] Raynos|14 years ago|reply For the record, I didn't write this library because I thought I could do it better.I wrote it because I didn't know about these other utilities / tools. [+] [-] mrspeaker|14 years ago|reply I hope ES.next gets a bunch of the goodness that is outlined in Harmony - this would mostly eradicate the need for stop-gap libraries like pd, or transpilers like CoffeeScript. http://wiki.ecmascript.org/doku.php?id=harmony:object_litera...And being able to do var obj = protoObj <| { ... properties ... } would be fantastic. If I that, and short function syntax then I'd be happy. [+] [-] Raynos|14 years ago|reply You need all three I'm afraid.We need an easy way to mixin/extend objects. var obj = protoObj <| mixin({ ... properties ... }, mixinA); We also need a solid way to create instances. object.create(obj); obj.constructor(); is just too verbose. There is some talk around making `new` work with object exemplars which would be great. [+] [-] Autre|14 years ago|reply Maybe I overlooked, but is there support for "super.method()" or something along those lines? [+] [-] Raynos|14 years ago|reply super is a nightmare to emulate and get "right". It has a bunch of weird edge cases you don't really want to think about.I promote code like var Cat = Object.make(Animal, { constructor: function() { Animal.constructor.apply(this, arguments); ... }, walk: function() { Animal.walk.apply(this, arguments); ... } }); Now compare:- Animal.walk.apply(this, arguments);- this.super.apply(this, arguments);- this.super.walk.apply(this, arguments);Using super doesn't fix verbosity, it only fixes hard coupling of Child class name to Super class name.For the complexities, edge cases and performance penalties a super implementation gives, it's simply not worth fixing this hard coupling.If you know of a super implementation that _just works_ please [Leave an answer on StackOverflow](http://stackoverflow.com/questions/8032566/emulate-super-in-...) load replies (2)
[+] [-] raganwald|14 years ago|reply “There are multiple similar prototypical OO utilies... All solve the same problem:”http://xkcd.com/927/ [+] [-] Raynos|14 years ago|reply For the record, I didn't write this library because I thought I could do it better.I wrote it because I didn't know about these other utilities / tools.
[+] [-] Raynos|14 years ago|reply For the record, I didn't write this library because I thought I could do it better.I wrote it because I didn't know about these other utilities / tools.
[+] [-] mrspeaker|14 years ago|reply I hope ES.next gets a bunch of the goodness that is outlined in Harmony - this would mostly eradicate the need for stop-gap libraries like pd, or transpilers like CoffeeScript. http://wiki.ecmascript.org/doku.php?id=harmony:object_litera...And being able to do var obj = protoObj <| { ... properties ... } would be fantastic. If I that, and short function syntax then I'd be happy. [+] [-] Raynos|14 years ago|reply You need all three I'm afraid.We need an easy way to mixin/extend objects. var obj = protoObj <| mixin({ ... properties ... }, mixinA); We also need a solid way to create instances. object.create(obj); obj.constructor(); is just too verbose. There is some talk around making `new` work with object exemplars which would be great.
[+] [-] Raynos|14 years ago|reply You need all three I'm afraid.We need an easy way to mixin/extend objects. var obj = protoObj <| mixin({ ... properties ... }, mixinA); We also need a solid way to create instances. object.create(obj); obj.constructor(); is just too verbose. There is some talk around making `new` work with object exemplars which would be great.
[+] [-] Autre|14 years ago|reply Maybe I overlooked, but is there support for "super.method()" or something along those lines? [+] [-] Raynos|14 years ago|reply super is a nightmare to emulate and get "right". It has a bunch of weird edge cases you don't really want to think about.I promote code like var Cat = Object.make(Animal, { constructor: function() { Animal.constructor.apply(this, arguments); ... }, walk: function() { Animal.walk.apply(this, arguments); ... } }); Now compare:- Animal.walk.apply(this, arguments);- this.super.apply(this, arguments);- this.super.walk.apply(this, arguments);Using super doesn't fix verbosity, it only fixes hard coupling of Child class name to Super class name.For the complexities, edge cases and performance penalties a super implementation gives, it's simply not worth fixing this hard coupling.If you know of a super implementation that _just works_ please [Leave an answer on StackOverflow](http://stackoverflow.com/questions/8032566/emulate-super-in-...) load replies (2)
[+] [-] Raynos|14 years ago|reply super is a nightmare to emulate and get "right". It has a bunch of weird edge cases you don't really want to think about.I promote code like var Cat = Object.make(Animal, { constructor: function() { Animal.constructor.apply(this, arguments); ... }, walk: function() { Animal.walk.apply(this, arguments); ... } }); Now compare:- Animal.walk.apply(this, arguments);- this.super.apply(this, arguments);- this.super.walk.apply(this, arguments);Using super doesn't fix verbosity, it only fixes hard coupling of Child class name to Super class name.For the complexities, edge cases and performance penalties a super implementation gives, it's simply not worth fixing this hard coupling.If you know of a super implementation that _just works_ please [Leave an answer on StackOverflow](http://stackoverflow.com/questions/8032566/emulate-super-in-...) load replies (2)
[+] [-] raganwald|14 years ago|reply
http://xkcd.com/927/
[+] [-] Raynos|14 years ago|reply
I wrote it because I didn't know about these other utilities / tools.
[+] [-] mrspeaker|14 years ago|reply
And being able to do
would be fantastic. If I that, and short function syntax then I'd be happy.[+] [-] Raynos|14 years ago|reply
We need an easy way to mixin/extend objects.
We also need a solid way to create instances. is just too verbose. There is some talk around making `new` work with object exemplars which would be great.[+] [-] Autre|14 years ago|reply
[+] [-] Raynos|14 years ago|reply
I promote code like
Now compare:- Animal.walk.apply(this, arguments);
- this.super.apply(this, arguments);
- this.super.walk.apply(this, arguments);
Using super doesn't fix verbosity, it only fixes hard coupling of Child class name to Super class name.
For the complexities, edge cases and performance penalties a super implementation gives, it's simply not worth fixing this hard coupling.
If you know of a super implementation that _just works_ please [Leave an answer on StackOverflow](http://stackoverflow.com/questions/8032566/emulate-super-in-...)