Using objects the Dojo way

bob becomes an object of Human.

by Piotr Zalewa

HTML

<div id='result'></div>

CSS

#result {
    margin-top: 10px;
    color: navy;
    font-weight: bold;
}

JavaScript

dojo.declare("Human",
    null,
    {
        isAlive: true,
        energy: 1,
        eat: function(){
            this.energy++;
        },
        printData: function(){
            dojo.create('p', {
                'innerHTML': 'energy: ' + this.energy 
            }, 'result');
        }
    }
);
bob = new Human();
//bob.energy === 1
bob.printData();
bob.eat();
//bob.energy === 2
bob.printData();