mirror of
https://github.com/flynx/object.js.git
synced 2025-10-30 11:00: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)
|
- [`parentProperty(..)`](#parentproperty)
|
||||||
- [`parentCall(..)`](#parentcall)
|
- [`parentCall(..)`](#parentcall)
|
||||||
- [`mixin(..)`](#mixin)
|
- [`mixin(..)`](#mixin)
|
||||||
|
- [`mixins(..)`](#mixins)
|
||||||
|
- [`hasMixin(..)`](#hasmixin)
|
||||||
- [`mixout(..)`](#mixout)
|
- [`mixout(..)`](#mixout)
|
||||||
- [`mixinFlat(..)`](#mixinflat)
|
- [`mixinFlat(..)`](#mixinflat)
|
||||||
- [`makeRawInstance(..)`](#makerawinstance)
|
- [`makeRawInstance(..)`](#makerawinstance)
|
||||||
- [`Constructor(..)` / `C(..)`](#constructor--c)
|
- [`Constructor(..)` / `C(..)`](#constructor--c)
|
||||||
- [Utilities](#utilities)
|
- [Utilities](#utilities)
|
||||||
- [`normalizeIndent(..)`](#normalizeindent)
|
- [`normalizeIndent(..)`](#normalizeindent)
|
||||||
|
- [`match(..)`](#match)
|
||||||
- [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)
|
||||||
@ -144,7 +147,6 @@ class B extends A {
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ npm install ig-object
|
$ npm install ig-object
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Or just download and drop [object.js](object.js) into your code.
|
Or just download and drop [object.js](object.js) into your code.
|
||||||
@ -634,13 +636,15 @@ match(base, obj)
|
|||||||
-> bool
|
-> bool
|
||||||
```
|
```
|
||||||
|
|
||||||
This relies on first level object structure to identify the target
|
This relies on first level object structure to match the input object, for
|
||||||
objects in the prototype chain, for a successful match the following
|
a successful match one of the following must apply:
|
||||||
must apply:
|
- object are identical
|
||||||
- attribute count must match,
|
|
||||||
- attribute names must match,
|
|
||||||
- attribute values must be 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...
|
// 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 =
|
var match =
|
||||||
module.match =
|
module.match =
|
||||||
function(base, obj){
|
function(base, obj){
|
||||||
@ -70,7 +79,6 @@ function(base, obj){
|
|||||||
if(typeof(base) != typeof(obj)){
|
if(typeof(base) != typeof(obj)){
|
||||||
return false }
|
return false }
|
||||||
// attr count...
|
// attr count...
|
||||||
//var o = Object.entries(obj)
|
|
||||||
var o = Object.keys(Object.getOwnPropertyDescriptors(obj))
|
var o = Object.keys(Object.getOwnPropertyDescriptors(obj))
|
||||||
if(Object.keys(Object.getOwnPropertyDescriptors(base)).length != o.length){
|
if(Object.keys(Object.getOwnPropertyDescriptors(base)).length != o.length){
|
||||||
return false }
|
return false }
|
||||||
@ -311,6 +319,16 @@ function(base, ...objects){
|
|||||||
|
|
||||||
// Get matching mixins...
|
// 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: if base matches directly callback(..) will get undefined as parent
|
||||||
// NOTE: this will also match base...
|
// NOTE: this will also match base...
|
||||||
var mixins =
|
var mixins =
|
||||||
@ -361,12 +379,6 @@ function(base, object){
|
|||||||
// -> base
|
// -> 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(..)
|
// NOTE: this is the opposite to mixin(..)
|
||||||
var mixout =
|
var mixout =
|
||||||
module.mixout =
|
module.mixout =
|
||||||
@ -384,7 +396,7 @@ function(base, ...objects){
|
|||||||
// NOTE: we are removing on a separate stage so as not to mess with
|
// NOTE: we are removing on a separate stage so as not to mess with
|
||||||
// mixins(..) iterating...
|
// mixins(..) iterating...
|
||||||
remove
|
remove
|
||||||
// XXX not sure why we need to reverse here -- needs more thought...
|
// XXX
|
||||||
.reverse()
|
.reverse()
|
||||||
.forEach(function(p){
|
.forEach(function(p){
|
||||||
p.__proto__ = p.__proto__.__proto__ })
|
p.__proto__ = p.__proto__.__proto__ })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user