git @ Cat's Eye Technologies Dipple / master javascript / inheritance.js
master

Tree @master (Download .tar.gz)

inheritance.js @masterraw · history · blame

// SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
// For more information, please refer to <https://unlicense.org/>
// SPDX-License-Identifier: Unlicense

function inherit(Child, Parent) {
    Child.prototype = new Parent();
    Child.prototype['super'] = Parent;
}

function Thing() {
    this.color = "yellow";
    this.init = function(weight) {
        this.weight = weight;
    }
    this.weigh = function() {
        alert("this " + this.color + " thing weighs " + this.weight);
    }
}
function Subthing() {
    this.color = "brown";
}
Subthing.prototype = new Thing();