173
rated 0 times
[
174]
[
1]
/ answers: 1 / hits: 7710
/ 6 Years ago, sun, july 29, 2018, 12:00:00
In ES5 it was possible to create multiple constructors for a class while keeping common parts to both using prototypes, as shown below
function Book() {
//just creates an empty book.
}
function Book(title, length, author) {
this.title = title;
this.Length = length;
this.author = author;
}
Book.prototype = {
ISBN: ,
Length: -1,
genre: ,
covering: ,
author: ,
currentPage: 0,
title: ,
flipTo: function FlipToAPage(pNum) {
this.currentPage = pNum;
},
turnPageForward: function turnForward() {
this.flipTo(this.currentPage++);
},
turnPageBackward: function turnBackward() {
this.flipTo(this.currentPage--);
}
};
var books = new Array(new Book(), new Book(First Edition, 350, Random));
I want to achieve the same result using ES6 class and constructor syntax
class Book{
constructore (){}
}
More From » ecmascript-6