From a341443b0715d62d7f9fd05a92b061365a1532dd Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 7 May 2020 21:20:20 +0300 Subject: [PATCH] docs... Signed-off-by: Alex A. Naanou --- README.md | 18 +++++++++++------- object.js | 30 +++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4c09474..4b24edd 100755 --- a/README.md +++ b/README.md @@ -129,12 +129,15 @@ class B extends A { - [`parentProperty(..)`](#parentproperty) - [`parentCall(..)`](#parentcall) - [`mixin(..)`](#mixin) + - [`mixins(..)`](#mixins) + - [`hasMixin(..)`](#hasmixin) - [`mixout(..)`](#mixout) - [`mixinFlat(..)`](#mixinflat) - [`makeRawInstance(..)`](#makerawinstance) - [`Constructor(..)` / `C(..)`](#constructor--c) - [Utilities](#utilities) - [`normalizeIndent(..)`](#normalizeindent) + - [`match(..)`](#match) - [Limitations](#limitations) - [Can not mix unrelated native types](#can-not-mix-unrelated-native-types) - [License](#license) @@ -144,7 +147,6 @@ class B extends A { ```shell $ npm install ig-object - ``` Or just download and drop [object.js](object.js) into your code. @@ -634,13 +636,15 @@ match(base, obj) -> bool ``` -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 relies on first level object structure to match the input object, for +a successful match one of the following must apply: +- object are identical +or: +- `typeof` matches _and_, +- attribute count matches _and_, +- attribute names match _and_, +- attribute values are identical. diff --git a/object.js b/object.js index 9557adb..422f3c0 100755 --- a/object.js +++ b/object.js @@ -59,7 +59,16 @@ function(text, tab_size){ // Match two objects... // -// XXX this will match any two objects with no enumerable keys... +// match(a, b) +// -> bool +// +// +// This will match objects iff: +// - if they are identical or +// - attr count is the same and, +// - attr names are the same and, +// - attr values are identical. +// var match = module.match = function(base, obj){ @@ -70,7 +79,6 @@ function(base, obj){ if(typeof(base) != typeof(obj)){ return false } // attr count... - //var o = Object.entries(obj) var o = Object.keys(Object.getOwnPropertyDescriptors(obj)) if(Object.keys(Object.getOwnPropertyDescriptors(base)).length != o.length){ return false } @@ -311,6 +319,16 @@ function(base, ...objects){ // Get matching mixins... // +// mixins(base, object[, callback]) +// mixins(base, list[, callback]) +// -> list +// +// +// callback(base, obj, parent) +// -> 'stop' | false +// -> undefined +// +// // NOTE: if base matches directly callback(..) will get undefined as parent // NOTE: this will also match base... var mixins = @@ -361,12 +379,6 @@ function(base, object){ // -> base // // -// This will match an object to a mixin iff: -// - if they are identical or -// - attr count is the same and, -// - attr names are the same and, -// - attr values are identical. -// // NOTE: this is the opposite to mixin(..) var mixout = module.mixout = @@ -384,7 +396,7 @@ function(base, ...objects){ // NOTE: we are removing on a separate stage so as not to mess with // mixins(..) iterating... remove - // XXX not sure why we need to reverse here -- needs more thought... + // XXX .reverse() .forEach(function(p){ p.__proto__ = p.__proto__.__proto__ })