MooTools – Program Structure


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.

Example

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.

<html>

   <head>
      <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({
            //properties
            width: 0,
            height: 0,
            
            //methods
            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);
         rec.details();
      </script>
   </head>
   
   <body>
   </body>
   
</html>

You will receive the following output −

Output