Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person {
- constructor (name) {
- this._name = name;
- }
- get name () {
- return this._name;
- }
- set name (name) {
- this._name = name;
- }
- is () {
- return "is unemployed!";
- }
- }
- class Worker extends Person {
- constructor (name, work) {
- super(name);
- this._work = work;
- }
- get work () {
- return this._work;
- }
- set work (work) {
- this._work = work;
- }
- is () {
- if (this._work) {
- return "is a " + this.work;
- } else {
- return super.is();
- }
- }
- }
- var people = [new Worker("Lajos"), new Worker("Jozsi", "car mechanic")];
- people.forEach(dude => {
- console.log( dude.name + " dude " + dude.is());
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement