I've recently been moving out of my comfort zone with JS, and come across a situation where it would make sense to share common functionality. What I've come up with is the following (concept only) code:
function subclass(parent, child) {
child.prototype = Object.create(parent.prototype)
}
function URL(str) {
this.value = str;
}
function HttpURL(str) {
this.value = str
}
subclass(URL, HttpURL)
URL.path = function() {
return this.value;
}
// ...
HttpURL.isSecure = function() {
this.value.substring(0, 8) === 'https://';
}
This code works as I expect it to work (making the "methods" on URL available on HttpURL, but not vice versa), but I wonder if it is "ethical" or if there is a better way of allowing this.