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.

NoSQL Databases Courses, Seminars, Consulting, and Development

MongoDB Design Patterns Meetup

The use of MongoDB involves with various cases in which we can overcome performance issues by implementing specific design patterns.

image of woman and database

Record Classes in Java

Learn how to define record classes in Java, and when to use record classes in your code. Stay up to date with the new Java features.

Accessibility | Career | Conferences | Design Patterns | JavaScript | Meetups | PHP | Podcasts | Python | Self Learning

Teaching Methodologies | Fullstack | C++ | C# | CSS | Node.js | Angular | Java | Go | Android | Kotlin | Swift | Academy

Front End Development | Scala | Architectures | Cloud | Big Data | Internet of Things | Kids Learn Programming

The Beauty of Code

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

Skip to content Update cookies preferences