From b6cacf5257ba9342c76bcee8a1e20b3c7bdf0a3b Mon Sep 17 00:00:00 2001 From: axelerant-hardik Date: Tue, 9 Jul 2024 21:04:52 +0530 Subject: [PATCH] LDT-311: Exercise - Polymorphism --- index.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/index.js b/index.js index e69de29..547f035 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,47 @@ +// Demonstrate polymorphism. +function HtmlElement() { + this.click = function() { + console.log('click'); + } +} + +HtmlElement.prototype.focus = function() { + console.log('focus'); +} + +// Select Element. +function HtmlSelectElement(items = []) { + this.items = items; + + this.addItem = function(item) { + this.items.push(item); + } + + this.removeItem = function(item) { + this.items.pop(item); + } + + this.render = function() { + let selectHtml = ''; + return selectHtml; + } +} + +HtmlSelectElement.prototype = new HtmlElement(); +HtmlSelectElement.prototype.constructor = HtmlSelectElement; + +// Image Element. +function HtmlImageElement(src = 'https://image') { + this.src = src; + + this.render = function () { + return ``; + } +} + +HtmlImageElement.prototype = new HtmlElement(); +HtmlImageElement.prototype.constructor = HtmlImageElement;