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—creating an instance of Dog


Let's create an instance of a Dog class by deploying the following the steps:

  1. Create an HTML document for this. Use the following code taken from our Dog class.

    <html>
    <head>
    <script type="text/javascript" src="mootools-1.2.1-core-nc.js">
    </script>
    <script type="text/javascript">
    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.' );
    },
    sit : function()
    {
    alert( this.options.name + ' is sitting.' );
    }
    });
    </script>
    </head>
    <body>
    </body>
    </html>
    

    Apart from taking out the comments, referencing the MooTools framework, and putting in the basic tags for an HTML document, nothing has changed so far.

  2. Create an instance of our Dog class, you can call the class instance anything you like, but I'll call mine simply myDog...