jeudi 13 septembre 2018

Object.prototype pattern

I do not understant, how to use Object.prototype pattern with classes (es6);

This is my code, I'm not sure, that I've used Object.prototype in the right way

    class Course{ 
     constructor(title, author) {
        this.title = title;
        this.author = author;
      }
    }


    Course.prototype.toString = function (arguments) {
        console.log(this.title + "... Author: " + this.author);
    };

    var course_1 = new Course("Bootstrap 4", "Paul");
    var course_2 = new Course("Design Patterns", "Paul");

    course_1.toString();
    course_2.toString();

}

Should I use something different?

Aucun commentaire:

Enregistrer un commentaire