From 79bb4f5564ffac41845f9f20d43b7f7369e913e9 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 6 May 2020 14:30:32 +0300 Subject: [PATCH] doc... Signed-off-by: Alex A. Naanou --- README.md | 36 ++++++++++++++++++++++++++++++++---- object.js | 4 +--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d0f1617..f8e97bd 100755 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ interchangeable with them. Here is a basic comparison: - +
@@ -491,6 +491,17 @@ makeRawInstance(, , ..) -> ``` +`makeRawInstance(..)` will do the following: +- Create an instance object + - get result of `.__new__(..)` if defined, or + - if prototype is a function or `.__call__(..)` is defined, create a + wrapper function, or + - if constructor's `.__proto__` is a function (constructor) use it + to create an instance, or + - use {}. +- Link the object into the prototype chain + + A shorthand to this is `Constructor.__rawinstance__(context, ..)`. @@ -504,6 +515,18 @@ Constructor(, , ) -> ``` +`Constructor(..)` essentially does the following: +- Creates a _constructor_ function, +- Sets constructor `.name` and `.toString(..)` for introspection, +- Creates `.__rawinstance__(..)` wrapper to `makeRawInstance(..)` +- Sets constructor `.__proto__`, `.prototype` and `.prototype.constructor`, +- Mixes in _constructor-mixin_ if given. + +The resulting _constructor_ function when called will: +- call constructor's `.__rawinstance__(..)` if defined or `makeRawInstance(..)` + to create an instance, +- call instance's `.__init__(..)` if present. + Shorthand to `Constructor(..)` ``` @@ -512,6 +535,11 @@ C(, ..) ``` +**Note:** +- All of the above are generic and will work on any JavaScript object, + e.g. `object.makeRawInstance(null, Array, 'a', 'b', 'c')` will happily + produce `['a', 'b', 'c']` and so on... + ## Utilities diff --git a/object.js b/object.js index 90fab21..3f96d67 100755 --- a/object.js +++ b/object.js @@ -661,6 +661,7 @@ function Constructor(name, a, b, c){ !!constructor_proto && (_constructor.__proto__ = constructor_proto) _constructor.prototype = proto + _constructor.prototype.constructor = _constructor // NOTE: this is intentionally last, this enables the user to override // any of the system methods... @@ -670,9 +671,6 @@ function Constructor(name, a, b, c){ _constructor, constructor_mixin) - // set constructor.prototype.constructor - _constructor.prototype.constructor = _constructor - return _constructor }
@@ -107,9 +107,9 @@ class B extends A { } ``` - Syntax pretty but _misleading_; - calling a constructor a class is not correct, -- `static` and instance definitions are not ordered, -- `.attr` is copied to every instance + calling a _constructor_ a class is not correct, +- `static` and instance definitions are not separated, +- lots of details done non-transparently under the hood.