Skip to content

Instantly share code, notes, and snippets.

@jeffmo
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffmo/bf30e7154ab3c894b740 to your computer and use it in GitHub Desktop.
Save jeffmo/bf30e7154ab3c894b740 to your computer and use it in GitHub Desktop.
class ParentClass {
constructor(controller, item_data, data) {
Object.assign(this, {
selectedClass: this.selectedClass || '' // should be set in subclasses
});
this.initializeItems();
}
initializeItems() {
// Does stuff with this.initializeItems
}
}
class ChildClass {
constructor(controller, item_data, data) {
if (!this.selectedClass) {
this.selectedClass = 'SubclassValue';
}
super(controller, item_data, data)
}
}
class ParentClass {
constructor(controller, item_data, data, opts) {
Object.assign(this, {
selectedClass: '' // should be set in subclasses
}, opts);
this.initializeItems();
}
initializeItems() {
// Does stuff with this.initializeItems
}
}
class ChildClass {
constructor(controller, item_data, data) {
super(controller, item_data, data, {
selectedClass: 'SubclassValue'
})
}
}
class TypeaheadBase {
constructor(name, placeholderText) {
var node = this.getInputNode();
node.placeholder = placeholderText;
node.name = name;
}
getInputNode() {
if (!this.inputNode) {
this.inputNode = document.getElementById('typeahead-node');
}
return this.inputNode;
}
}
class MyFooTypeahead extends TypeaheadBase{
constructor(name) {
var inputNode = this.getInputNode(); // nope!
var placeholderText =
inputNode.className.indexOf('Blue')
? 'I Am Blue'
: 'I Am Not Blue';
super('Foo', placeholderText);
}
}
class TypeaheadBase {
constructor(name, placeholderText) {
var node = this.getInputNode();
node.placeholder = placeholderText;
node.name = name;
}
getInputNode() {
if (!this.inputNode) {
this.inputNode = document.getElementById('typeahead-node');
}
return this.inputNode;
}
}
class MyFooTypeahead extends TypeaheadBase {
constructor(name) {
var inputNode = this.getInputNode();
var placeholderText =
inputNode.className.indexOf('Blue')
? 'I Am Blue'
: 'I Am Not Blue';
TypeaheadBase.call(this, 'Foo', placeholderText);
}
}
class BaseInputValidator {
constructor(wrapper, field, position) {
this.setupListeners();
}
setupListeners() {
// default listeners setup
}
}
class ChildInputValidator extends BaseInputValidator {
constructor(wrapper, field, position, type) {
this.domElements = document.querySelectorAll( /* ... */ );
// Need to call this at the end since setupListeners needs
// this.domElements to be initialized
super(wrapper, field, position);
}
setupListeners() {
this.domElements.forEach(function(el) {
// do stuff
});
}
}
class BaseInputValidator {
constructor(wrapper, field, position) {
this.setupListeners();
}
setupListeners() {
// default listeners setup
}
}
class ChildInputValidator extends BaseInputValidator {
constructor(wrapper, field, position, type) {
super(wrapper, field, position);
}
setupListeners() {
document.querySelectorAll( /* ... */ ).forEach(function(el) {
// do stuff
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment