jOOPL: Simple inheritance

Class "B" inherits "A" in a namespace called "joopl.enjoyment".

by MatĂ­as Fidemraizer

HTML

<script src="http://cdn.jsdelivr.net/joopl/2.5.2/joopl.min.js"></script>
<span id="result"></span>

JavaScript

$namespace.using("joopl.enjoyment", function(enjoyment) {
    enjoyment.declareClass("A", {
        members: {
            goEnjoy: function() {
                return "this rocks!";
            }
        }
    });
    
    enjoyment.declareClass("B", {
        inherits: enjoyment.A,
        members: {
            enjoyMore: function() {
                // goEnjoy() is available because it has been
                // inherited!
                 return this.goEnjoy() + " yeah!";   
            }
        }
    });
    
    var b = new enjoyment.B();
    
    // enjoyMore() call will return "this rocks! yeah!"
    var text = b.enjoyMore();
    
    document.getElementById("result").appendChild(
        document.createTextNode(text)
    );
});