From 4d247872447cc55d9ef754e1a1f14ed2f346b302 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 31 May 2023 15:58:05 +0300 Subject: [PATCH] tweaking... Signed-off-by: Alex A. Naanou --- js-oop.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/js-oop.js b/js-oop.js index 8a2ac87..954f95b 100755 --- a/js-oop.js +++ b/js-oop.js @@ -24,6 +24,13 @@ var b = Object.create(a) b.z = 3 +// Another way to do this: + + var b = { + __proto__: a, + z: 3, + } + // The object 'b' now has both access to it's own attributes ('z') and // attributes of 'a' ('x' and 'y') @@ -68,7 +75,8 @@ Object.keys(b) // -> z // show all accessible keys... - for(var k in b){ console.log(k) } + for(var k in b){ + console.log(k) } // -> x, y, z // Another way to test if the attribute is own/local @@ -100,9 +108,9 @@ // this: function clone(from){ - var o = {} - o.__proto__ = from - return o + return { + __proto__: from, + } } var c = clone(b)