From a127225f67a4602922f7cc23787354dc5cd0adb2 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 2 May 2020 00:48:55 +0300 Subject: [PATCH] doc tweak... Signed-off-by: Alex A. Naanou --- README.md | 80 +++++++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index acea3b7..e62e646 100755 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ several advantages: - Simple way to define callable instances (including a-la _Python's_ `.__call__(..)`) - Less restrictive: - - `new` is optional - - all input components are reusable + - `new` is optional + - all input components are reusable - no artificial restrictions Disadvantages compared to the `class` syntax: @@ -76,33 +76,33 @@ c instanceof A // -> true ### Inheritance ```javascript // -// Base <--- Item +// Base <--- Item // var Base = object.Constructor('Base', { - proto_attr: 'prototype attr value', + proto_attr: 'prototype attr value', - get prop(){ - return 'propery value' }, + get prop(){ + return 'propery value' }, - method: function(){ - console.log('Base.method()') }, + method: function(){ + console.log('Base.method()') }, - // initializer... - __init__: function(){ - this.instance_attr = 'instance' - }, + // initializer... + __init__: function(){ + this.instance_attr = 'instance' + }, }) var Item = object.Constructor('Item', { - // inherit from Base... - __proto__: Base.prototype, + // inherit from Base... + __proto__: Base.prototype, - __init__: function(){ - // call the "super" method... - object.parentCall(this.prototype.__init__, this) + __init__: function(){ + // call the "super" method... + object.parentCall(this.prototype.__init__, this) - this.item_attr = 'instance attribute value' - }, + this.item_attr = 'instance attribute value' + }, }) ``` @@ -112,11 +112,11 @@ var Item = object.Constructor('Item', { ```javascript var Action = object.Constructor('Action', - // constructor as a function... - function(context, ...args){ - // return the instance... - return this - }) + // constructor as a function... + function(context, ...args){ + // return the instance... + return this + }) var action = new Action() @@ -131,9 +131,9 @@ action() // attributes and props. var Action2 = object.Constructor('Action2', { - __call__: function(context, ...args){ - return this - }, + __call__: function(context, ...args){ + return this + }, }) ``` @@ -143,7 +143,7 @@ method receive a `context` argument in addition to `this` context, those represent the two contexts relevant to the callable instance: - Internal context (`this`) This always references the instance being called -- External context (`context`) +- External context (`context`) This is the object the instance is called from, i.e. the call _context_ (`window` or `global` by default) @@ -155,9 +155,9 @@ user's responsibility to call `.__call__(..)` method. ```javascript var LowLevel = object.Constructor('LowLevel', { - __new__: function(context, ...args){ - return {} - }, + __new__: function(context, ...args){ + return {} + }, }) ``` @@ -171,7 +171,7 @@ The external context is the same as above. Contexts: - Internal context (`this`) References the `.prototype` of the constructor. -- External context (`context`) +- External context (`context`) This is the object the instance is called from, i.e. the call _context_ (`window` or `global` by default), the same as for function constructor and `.__call__(..)`. @@ -198,7 +198,7 @@ Get sources for attribute ``` sources(, ) sources(, , ) - -> + -> ``` @@ -209,7 +209,7 @@ parent(, ) -> undefined parent(, ) - -> + -> -> undefined ``` @@ -231,11 +231,11 @@ parentProperty(, ) Get parent method and call it ``` parentCall(, , ) - -> + -> -> undefined parentCall(, ) - -> + -> -> undefined ``` @@ -243,14 +243,14 @@ parentCall(, ) Mixin objects into a prototype chain ``` mixin(, , ..) - -> + -> ``` Mixin contents of objects into one ``` mixinFlat(, , ..) - -> + -> ``` This is like `Object.assign(..)` but copies property objects rather than property values. @@ -269,14 +269,14 @@ Define an object constructor ``` Constructor(, ) Constructor(, , ) - -> + -> ``` Shorthand to `Constructor(..)` ``` C(, ..) - -> + -> ```