MooTools - Program Structure

MooTools is a tool which can be used to design object-oriented models. Let us discuss in this chapter a simple example of MooTools library.


Here we will design a model named Rectangle using Class. For this, we need to declare the properties — Width and Height.

Take a look at the following code, and save it into sample.html.


      <script type = "text/javascript" src = "MooTools-Core-1.6.0.js"></script>
      <script type = "text/javascript" src = "MooTools-More-1.6.0.js"></script>
      <script type = "text/javaScript">
         var Rectangle = new Class({
            width: 0,
            height: 0,
            initialize: function(widthVal, heightVal) {
               this.width = widthVal;
               this.height = heightVal;
            details: function() {
               document.write("Welcome to MooTools demo program");
               document.write("Width: "+this.width+" Height: "+this.height);
         var rec = new Rectangle(5,4);

You will receive the following output −