Quick actions

cmd+k|ctrl+k

Navigation

Languages

JS 4 OOP Pillars

Snippet info

Language

JavaScript

Visibility

public

Author

nacht777

Created

2022-09-29T12:06:52.913131Z

Updated

2022-09-29T12:06:52.913131Z

//Encapsulation

//Inheritance
class Mail {
    constructor(author) {
        this.from = author;
        this._contacts = [];
    }
    sendMessage(msg, to) {
        console.log(`you send: ${msg} to ${to} from ${this.from}`);
        this._contacts.push(to);
    }
    showAllContacts() {
        return this._contacts;
    }
}

class WhatsApp extends Mail {
    constructor(author) {
        super(author);
        this.username = 'dicoding';
        this.isBussinessAccount = true;
    }
    myProfile() {
        return `my name ${this.username}, is ${this.isBussinessAccount ? 'Business' : 'Personal'}`;
    }
}

const wa1 = new WhatsApp('080111000222');
console.log(wa1.myProfile());
INFO