From a8783a284efd0a105d8b12f88d760df9ec97d03d Mon Sep 17 00:00:00 2001
From: Sascha Schulz <sschulz@dh-software.de>
Date: Di, 25 Apr 2023 16:09:46 +0200
Subject: [PATCH] add examples for functions, constructors, objects and inheritance

---
 templates/007-js/constructors.js |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/templates/007-js/constructors.js b/templates/007-js/constructors.js
index e7714df..2d008ad 100644
--- a/templates/007-js/constructors.js
+++ b/templates/007-js/constructors.js
@@ -3,6 +3,13 @@
     this.b = b;
 }
 
-const r = new Rectangle(2, 3);
+// jede Funktion besitzt einen Prototypen
+Rectangle.prototype.getArea = function() {
+    return this.a * this.b;
+}
 
-console.log(r.a);
+const r1 = new Rectangle(2, 3);
+const r2 = new Rectangle(4, 5);
+
+console.log(r1.getArea());
+console.log(r2.getArea());

--
Gitblit v1.9.3