Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-05-06 14:54:16 +03:00
parent 9af75efc8f
commit 98aa84ee9f

View File

@ -131,7 +131,17 @@ class B extends A {
- [Inheriting from native constructor objects](#inheriting-from-native-constructor-objects) - [Inheriting from native constructor objects](#inheriting-from-native-constructor-objects)
- [Extending native `.constructor(..)`](#extending-native-constructor) - [Extending native `.constructor(..)`](#extending-native-constructor)
- [Components](#components) - [Components](#components)
- [`sources(..)`](#sources)
- [`parent(..)`](#parent)
- [`parentProperty(..)`](#parentproperty)
- [`parentCall(..)`](#parentcall)
- [`mixin(..)`](#mixin)
- [`mixout(..)`](#mixout)
- [`mixinFlat(..)`](#mixinflat)
- [`makeRawInstance(..)`](#makerawinstance)
- [`Constructor(..)` / `C(..)`](#constructor--c)
- [Utilities](#utilities) - [Utilities](#utilities)
- [`normalizeIndent(..)`](#normalizeindent)
- [Limitations](#limitations) - [Limitations](#limitations)
- [Can not mix unrelated native types](#can-not-mix-unrelated-native-types) - [Can not mix unrelated native types](#can-not-mix-unrelated-native-types)
- [License](#license) - [License](#license)
@ -423,6 +433,11 @@ var myArray = object.Constructor('myArray', Array, {
## Components ## Components
Note that all of the bellow 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...
### `sources(..)` ### `sources(..)`
Get sources for attribute Get sources for attribute
@ -456,7 +471,6 @@ between these references and will always return the second one._
### `parentProperty(..)` ### `parentProperty(..)`
Get parent property descriptor Get parent property descriptor
``` ```
parentProperty(<prototype>, <name>) parentProperty(<prototype>, <name>)
-> <prop-descriptor> -> <prop-descriptor>
@ -480,21 +494,36 @@ parentCall(<method>, <this>)
### `mixin(..)` ### `mixin(..)`
Mixin objects into a prototype chain _Mixin_ objects into a prototype chain
``` ```
mixin(<root>, <object>, ..) mixin(<base>, <object>, ..)
-> <root> -> <base>
``` ```
This will link the base `.__proto__` to the last _mixin_ in chain,
keeping the prototype visibility the same.
This will copy the content of each input object without touching the
objects themselves, making them fully reusable.
### `mixout(..)` ### `mixout(..)`
Mix objects out of a prototype chain Remove objects out of a prototype chain
``` ```
mixout(<root>, <object>, ..) mixout(<base>, <object>, ..)
-> <root> -> <base>
``` ```
This relies on first level object structure to identify the target
objects in the prototype chain, for a successful match the following
must apply:
- attribute count must match,
- attribute names must match,
- attribute values must be identical.
This is the opposite of `mixin(..)`
### `mixinFlat(..)` ### `mixinFlat(..)`
@ -503,8 +532,8 @@ Mixin contents of objects into one
mixinFlat(<root>, <object>, ..) mixinFlat(<root>, <object>, ..)
-> <object> -> <object>
``` ```
This is like `Object.assign(..)` but copies property objects rather than This is like `Object.assign(..)` but copies property descriptors rather
property values. than property values.
### `makeRawInstance(..)` ### `makeRawInstance(..)`
@ -529,7 +558,7 @@ makeRawInstance(<context>, <constructor>, ..)
A shorthand to this is `Constructor.__rawinstance__(context, ..)`. A shorthand to this is `Constructor.__rawinstance__(context, ..)`.
### `Constructor(..)` ### `Constructor(..)` / `C(..)`
Define an object constructor Define an object constructor
``` ```
@ -554,8 +583,6 @@ The resulting _constructor_ function when called will:
- call instance's `.__init__(..)` if present. - call instance's `.__init__(..)` if present.
### `C(..)`
Shorthand to `Constructor(..)` Shorthand to `Constructor(..)`
``` ```
C(<name>, ..) C(<name>, ..)
@ -563,14 +590,11 @@ C(<name>, ..)
``` ```
**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 ## Utilities
### `normalizeIndent(..)`
Align text to shortest leading whitespace Align text to shortest leading whitespace
``` ```
normalizeIndent(<text>) normalizeIndent(<text>)