Skip to content

Instantly share code, notes, and snippets.

@A
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save A/8cd490d89ce6c9b18800 to your computer and use it in GitHub Desktop.

Select an option

Save A/8cd490d89ce6c9b18800 to your computer and use it in GitHub Desktop.
Inheritance problems on ES2015 with properties before 'super'.
class View {
constructor() {
// require tagName and className to create element
}
}
class Input extends View {
constructor(...args) {
this.tagName = 'input';
this.className = 'form-control input';
super(...args);
}
}
class TextArea extends Input {
constructor(...args) {
this.tagName = 'textarea';
this.className = 'form-control textarea';
super(...args);
}
}
console.log('create new Input');
var input = new Input();
console.assert(input.tagName === 'input'); //ok
console.assert(input.className = 'form-control input'); // ok
console.log('create new TextArea');
var textarea = new TextArea();
console.assert(textarea.tagName === 'textarea'); // fail
console.assert(textarea.className === 'form-control textarea'); // fail
// Simplest example
class A {
x = 5;
}
class B extends A {
x = 0;
}
let b = new B();
console.log(b.x); // 5
@A

A commented Feb 3, 2015

Copy link
Copy Markdown
Author

Link to traceur playground with this code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment