Book Image

MooTools 1.2 Beginner's Guide

Book Image

MooTools 1.2 Beginner's Guide

Overview of this book

MooTools is a simple-to-use JavaScript library, ideal for people with basic JavaScript skills who want to elevate their web applications to a superior level. If you're a newcomer to MooTools looking to build dynamic, rich, and user-interactive web site applications this beginner's guide with its easy-to-follow step-by-step instructions is all you need to rapidly get to grips with MooTools.
Table of Contents (14 chapters)
MooTools 1.2 Beginner's Guide
Credits
About the Authors
About the Reviewer
Preface

Time for action—extending the ShowDog class with the Dog class


Let's see how we can extend our Dog class using the Extends property:

  1. Let's clean up the Dogs class first by removing the things we don't need any more to tidy up our code. We'll delete the .sit() class method, the myDog.bark() call, and the document.write's that we used to show the option property values of myDog. Here's our revised code:

    <html>
    <head>
    <script type="text/javascript" src="mootools-1.2.1-core-nc.js"> </script>
    <script type="text/javascript">
    window.addEvent('domready', function()
    {
    var Dog = new Class(
    {
    Implements : [ Options ],
    options :
    {
    name : 'Barkee',
    type : 'Poodle',
    age : 4
    },
    initialize : function( options )
    {
    this.setOptions( options );
    },
    bark : function()
    {
    alert( this.options.name + ' is barking.' );
    }
    });
    });
    </script>
    </head>
    <body>
    </body>
    </html>
    
  2. Create the ShowDog class right below the Dog class. Use the following code:

    var ShowDog ...