Loading

Abstraction

  • Abstraction is a way of creating a simple model of more complex real-world entities, which contains the only important properties from the perspective of the context of an application.

Example:

<!DOCTYPE html>
<html>

<body>

    <script>
        //Creating a constructor function
        function Vehicle() {
            this.vehicleName = "vehicleName";
            throw new Error("You cannot create an instance of Abstract Class");
        }
        Vehicle.prototype.display = function () {
            return "Vehicle is: " + this.vehicleName;
        }
        //Creating a constructor function
        function Bike(vehicleName) {
            this.vehicleName = vehicleName;
        }
        //Creating object without using the function constructor
        Bike.prototype = Object.create(Vehicle.prototype);
        var bike = new Bike("Honda");
        document.writeln(bike.display());


    </script>

</body>

</html>

Output:

Vehicle is: Honda