Abstraction

An abstraction is a way of hiding the implementation details and showing only the functionality to the users. In other words, it ignores the irrelevant details and shows only the required one. This reduces complexity because we can just see the methods and what the class can do. Now the idea of abstraction also helps when we have private variables and private methods in JavaScript.


function Person(name, country) {
    this.name = name;
    this.country = country;
    let language = "english";
    this.speak = function () {
        return think()+ " and " + this.name + " can speak " + language;

    }
    let think = function () {
        return "Think by " + language
    }
}

const tim = new Person("tim", "USA");
console.log(tim.speak());
Think by english and tim can speak english

let think is a part of Abstraction method. Also, a language field and a think method is only used in Person function. When you create a tim object you can not use the field and method directly like private Java.

Leave a Reply

Your email address will not be published.

ANOTE.DEV