class properties inheritance

Claude Pache claude.pache at gmail.com
Mon Dec 29 04:36:08 PST 2014


> Le 28 déc. 2014 à 23:14, Frankie Bagnardi <f.bagnardi at gmail.com> a écrit :
> 
> That's why you call super(); as the first line in the constructor.

The true rule is not: "call super() in the first line in the constructor"; it is: "don't reference `this` before calling the super constructor".

—Claude

> 
> On Sun, Dec 28, 2014 at 2:42 PM, Антон Шувалов <anton at shuvalov.info> wrote:
> Hi, guys! I'm confused with class properties. With prototype chains I can setup kinda default values which being replaced by values from children. But replacing become hard to work with classes. For example, we have simple module, some backbone view:
> 
> ```js
> class BaseView extends Backbone.View {
>   constructor() {
>     this.tagName = 'div';
>     super(); // create element from this.tagName value
>   }
> }
> ```
> 
> And now we create inherited view:
> 
> ```js
> class Span extends BaseView {
>   constructor() {
>     this.tagName = 'span'
>     super();
>   }
> }
> ```
> 
> But all `this` variables will be replaced by parent, not by child. It's kinda weird. Another example with prototype chains works fine:
> 
> ```js
> var BaseView = Backbone.View.extends({
>   tagName: 'div'
> })
> ```
> 
> ```js
> var Span = Backbone.View.extends({
>   tagName: 'span'
> });
> ```
> 
> How I can do similar things with es6 classes? Sorry if this question is already discussed.
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list