From ead4ed4868db7260d5ce26b9fd3b2d62d25eaf32 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 6 May 2020 03:15:39 +0300 Subject: [PATCH] tweaking docs... Signed-off-by: Alex A. Naanou --- README.md | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7464bf3..e072e4e 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ object model and interfaces. This is an alternative to the ES6 `class` syntax in JavaScript and provides several advantages: -- Simple way to define instance and "class" methods, properties and attributes, +- Simple way to define instance and "class" (constructor) methods, + properties and attributes, - Uniform and minimalistic definition syntax based on basic JavaScript object syntax, no special cases, special syntax or _"the same but slightly different"_ ways to do things, @@ -17,6 +18,8 @@ several advantages: and `.__init__(..)` methods) - Simple way to define callable instances (including a-la _Python's_ `.__call__(..)`) +- produces fully introspectable constructors/instances, i.e. no direct + way to define "private" attributes or methods. - Less restrictive: - `new` is optional - all input components are reusable @@ -26,20 +29,23 @@ Disadvantages compared to the `class` syntax: - No _syntactic sugar_ - Slightly more complicated calling of `parent` (_super_) methods + + +Here is a basic comparison: - -
+ _object.js_ ```javascript -var Base = object.Constructor('X', Array, { +var L = object.Constructor('L', Array, { constructor_attr: 'constructor', method: function(){ return 'constructor' }, }, { - // prototype attribute... + // prototype attribute (inherited)... attr: 'prototype', get prop(){ @@ -51,19 +57,24 @@ var Base = object.Constructor('X', Array, { }) ``` +- Clear separation of constructor and `.prototype` data: + - First block (optional) is merged with constructor + - Second block is the `.prototype` +- no direct way to define "private" + + _ES6_ ```javascript -class X extends Array { +class L extends Array { static constructor_attr = 'class' static method(){ return 'class' } - // instance attribute with default value... + // instance attribute (copied)... attr = 'instance' get prop(){ @@ -76,12 +87,15 @@ class X extends Array { } } ``` +- `static` and instance definitions are mixed within the body, +- `.attr` is copied to every instance
+ ## Contents - [object.js](#objectjs) - [Contents](#contents)