function Book(title, price) { this.title = title; this.price = price; this.printTitle = () => console.log(this.title); } function BookPrototype(prototype) { this.prototype = prototype; this.clone = () => { let book = new Book(); book.title = prototype.title; book.price = prototype.price; return book; }; } let sampleBook = new Book(‘JavaScript’, 15); let prototype = new BookPrototype(sampleBook); let book = prototype.clone(); book.printTitle();
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter