diff --git a/Object.js b/Object.js index 7be22cd..c819e43 100644 --- a/Object.js +++ b/Object.js @@ -68,6 +68,7 @@ object.Mixin('ObjectMixin', 'soft', { res[key] = obj[key] return res }, constructor == null ? + //Object.create(obj.__proto__) {} : constructor()) }, diff --git a/README.md b/README.md index 48dc7b3..9d6fe16 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ the module dealing with that constructor (`Array` in this case): // require `ig-types/`... require('ig-types/Array') ``` -Note that type patching modules are mostly independent. +Note that type patching modules are _mostly_ independent. And to import specific library modules only: ```javascript @@ -188,15 +188,20 @@ var containers = require('ig-types/containers') require('ig-types/Object') ``` +Note that this module imports from +[`object.js`](https://github.com/flynx/object.js) and +[`object-run.js`](https://github.com/flynx/object-run.js), +see those modules for more details. + + ### `Object.deepKeys(..)` +Get list of keys from all objects in the prototype chain. ```bnf Object.deepKeys() -> ``` -Get list of keys from all objects in the prototype chain. - This is different from `Object.keys(..)` which only gets _own_ keys from the current object. @@ -213,39 +218,111 @@ Object.keys(b) // -> ['y'] Object.deepKeys(b) // -> ['x', 'y'] ``` +For more details see: +https://github.com/flynx/object.js#deepkeys + + ### `Object.copy(..)` (EXPERIMENTAL) +Create a copy of `` ```bnf Object.copy() -> -``` -Create a copy of `` +Object.copy(, ) + -> +``` This will: - create a blank `` - link `` to the same prototype chain -- copy all _own_ keys from `` to `` +- assign all _own_ keys from `` to `` -Note that this will make no attempt to clone object type. +This is similar to `Object.clone(..)` but instead of creating a new descendant of +the input object with no data this will instead create a new sibling with a copy +of the instance data. -_XXX not yet sure how useful this is._ +`` if given is called to create the instance to be populated, +otherwise `Object.create()` is used. + +Note that `.assign(..)` is used to copy data, thus properties will be copied as values, to copy instance properties use `object.js`'s +[`.mixinFlat(..)`](https://github.com/flynx/object.js#mixinflat). + +Note that this will make no attempt to clone object type, a `` +should be passed manually if any instance type other that `Object` is required. ### `Object.flatCopy(..)` +Copy all attributes from the prototype chain of `` into ``. ```bnf Object.flatCopy() -> + +Object.flatCopy(, ) + -> ``` -Copy all attributes from the prototype chain of `` into ``. +This is different to [`.copy(..)`](#objectcopy-experimental) in that if +no `` is given `` will _not_ be linked into the +prototype chain of ``, if this behavior is desired use `o => Object.create(o)` +as the ``. ### `Object.match(..)` +Attribute/value match two objects (non-recursive). +```bnf +Object.match(, ) + -> +``` + +Objects `A` and `B` match iff: +- `A` and `B` are _identical_, i.e. `A === B` + +or +- `typeof A == typeof B` _and_, +- `A` and `B` have the same number of attributes _and_, +- attribute names match _and_, +- attribute values are _identical_. + +And for a less strict match: +```bnf +Object.match(, , true) + -> +``` +Like the default case but uses _equality_ instead of _identity_ to match values. + + +For more details see: +https://github.com/flynx/object.js#match + + + + ### `Object.matchPartial(..)` +```bnf +Object.matchPartial(, ) + -> + +Object.matchPartial(, , true) + -> +``` +Like `.match(..)` but will check for a _partial_ match, i.e. when `` is a non-strict subset of ``. + +For more details see: +https://github.com/flynx/object.js#matchpartial + + + + ### `.run(..)` ```bnf @@ -279,13 +356,13 @@ console.log(L) // -> [1, 2, 6, 8] $ npm install -s object-run ``` -For more info see: +For more details see: https://github.com/flynx/object-run.js ### `Object.sort(..)` -Sort `` attributes (same as `Array`'s `.sort(..)`) +Sort `` attributes (similar to `Array`'s `.sort(..)`) ```bnf Object.sort() -> @@ -370,7 +447,7 @@ Roll `` in-place left. -> ``` -To roll right pass a negative `n` to `.rol(..)`. +To roll _right_ pass a negative `n` to `.rol(..)`. ### `.compact()` @@ -399,15 +476,22 @@ L.compact().length Note that this is different from `.length` in that writing to `.len` has no effect. + ### `.unique()` / `.tailUnique()` Generate an array with all duplicate elements removed. - ```bnf .unique() -> + +.tailUnique() + -> ``` +The difference between the two versions is in that `.unique(..)` keeps the +first occurrence of a value while `.tailUnique(..)` keeps the last. + + ### `.trim()` / `.trimStart()` / `.trimEnd()` Copy array removing empty slots from array start, end or both. @@ -422,6 +506,9 @@ Copy array removing empty slots from array start, end or both. -> ``` +This is similar to `String`'s equivalent methods but removing _empty_ slots +instead of spaces. + ### `.cmp(..)` @@ -432,20 +519,27 @@ Compare two arrays. ``` This will return `true` if: -- `` === `` or, +- ` === ` + +or - lengths are the same and, - values on the same positions are equal. + + ### `.setCmp(..)` Compare to arrays ignoring element order and count. - ```bnf .setCmp() -> ``` + ### `.sortAs(..)` Sort array as a different array. diff --git a/generator.js b/generator.js index 99ab30a..203e4d9 100644 --- a/generator.js +++ b/generator.js @@ -251,6 +251,9 @@ object.Mixin('GeneratorProtoMixin', 'soft', { return this.promise().catch(func) }, finally: function(func){ return this.promise().finally(func) }, + + + // XXX EXPERIMENTAL... })