Inheritance using MooTools PRO

When using MooTools, in order to define a class that extends another we should use the Extends key and assign it with the name of the parent class as its value. In order to invoke a method that was overridden we should use this.parent.

<!DOCTYPE html>
<html>
<head>
    <title>mootools functions binding demo</title>
    <script type="text/javascript" src="mootools-core-1.4.5-full-compat.js">
    </script>
    <script type="text/javascript">
        var Person = new Class({
            //properties
            fName: '',
            lName: '',
            id: 0,
            //constructor
            initialize: function(first,last,idVal)
            {
                this.fName = first;
                this.lName = last;
                this.id = idVal;
            },
            //methods
            sleep: function()
            {
                document.write(this.fName + ' is sleeping.' + "<br>");
            },
            talk: function()
            {
                document.write(this.fName + ' is talking.' + "<br>");
            }
        });
        var Student = new Class({
            //inheritance
            Extends:Person,
            //properties
            average:0,
            //constructor
            initialize: function(first,last,idVal,avgVal)
            {
                this.parent(first,last,idVal);
                average = avgVal;
            },
            //methods
            printDetails: function()
            {
                document.write(this.fName+" "+this.lName+" "+this.id+" "+average);
            }
        });
        var std = new Student("moshe","jonas",123123,98);
        std.printDetails();
    </script>
</head>
<body>

</body>
</html>

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

Share:

The Visitor Design Pattern

The Visitor Design Pattern

The visitor design pattern allows us to add operations to objects that already exist without modifying their classes and without extending them.

What are Anti Patterns?

Anti Patterns

Unlike design patterns, anti patterns just seem to be a solution. However, they are not a solution and they cause additional costs.

Virtual Threads in Java Professional Seminar

Virtual Threads in Java

The use of virtual threads can assist us with improving the performance of our code. Learn how to use virtual threads effectively.

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences