When defining a class using the MooTools framework we can include the definition of a constructor inside of it. We just need to add to the object we pass over to Class constructor the ‘initialize’ key with the constructor function as its value.

<!DOCTYPE html>
    <title>mootools functions binding demo</title>
    <script type="text/javascript" src="mootools-core-1.4.5-full-compat.js">
    <script type="text/javascript">
        var Person = new Class({
            name: '',
            id: 0,
            initialize: function(nameVal,idVal)
                this.name = nameVal;
                this.id = idVal;
            sleep: function()
                document.write(this.name + ' is sleeping.' + "<br>");
            talk: function()
                document.write(this.name + ' is talking.' + "<br>");
        var a = new Person('david',123123);
        var b = new Person('mike',543543);


The following video clip shows the execution of this code, overviews it and explains.

Leave a Reply

Your email address will not be published. Required fields are marked *