From fa8856f84fc266d9697a22d4e7e3fef01d71a3e8 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 10 Jun 2023 14:59:13 +0300 Subject: [PATCH] added inheriting from builtins... Signed-off-by: Alex A. Naanou --- js-types-n-oop.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/js-types-n-oop.js b/js-types-n-oop.js index 0f9c0d8..5a58434 100755 --- a/js-types-n-oop.js +++ b/js-types-n-oop.js @@ -85,6 +85,7 @@ // Type checking // + typeof(42) // -> 'number' typeof('meaning of life') // -> 'string' @@ -145,6 +146,7 @@ __proto__: A.prototype, } +// XXX a safer way -- now we can forget new... function B(){ var obj = { @@ -163,8 +165,29 @@ : { __proto__: C.prototype } return obj } + // make C instances related to B... + C.prototype.__proto__ = B.prototype - // XXX extending the chain.... + + +// Extending builtin types +// + +// XXX Reflect.construct(Function, args, newConstructor) +// mainly usefull if the resulting instance has to be of a builtin +// type like a function (callable) or an array... + + + +// Classes and JavaScript +// +// Since the class syntax is simply a more restrictive way to do the +// same as the above, in addition to introducing more "the same but +// slightly different" ways to define functions and methods thus adding +// lots of new details, pitfalls and nuances that give us essentially +// the same functionaly that already existed in the language with +// the onus of additional complexity, we will be completely ignoring +// them in this document.