mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 10:30:08 +00:00
docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
86ffc914c3
commit
a341443b07
18
README.md
18
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.
|
||||
|
||||
|
||||
|
||||
|
||||
30
object.js
30
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__ })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user