-
-
Save jeffmo/bf30e7154ab3c894b740 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
}) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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