mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 18:40:08 +00:00
refactoring and docs... nees testing...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ac79aca5a8
commit
563d9df54f
48
object.js
48
object.js
@ -68,33 +68,11 @@ function(method, name, that){
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
// Create an object and mix in sets of methods/props/attrs...
|
// Mix a set of methods/props/attrs into an object...
|
||||||
//
|
//
|
||||||
// mixin(root, object, ...)
|
// mixinFlat(root, object, ...)
|
||||||
// -> object
|
// -> root
|
||||||
//
|
//
|
||||||
// This will create a new object per set of methods given and
|
|
||||||
// Object.assign(..) the method set into this object leaving the
|
|
||||||
// original objects intact.
|
|
||||||
//
|
|
||||||
// root <-- object1_copy <-- .. <-- objectN_copy
|
|
||||||
//
|
|
||||||
// XXX use .mixinFlat(..) inside...
|
|
||||||
var mixin =
|
|
||||||
module.mixin =
|
|
||||||
function(root, ...objects){
|
|
||||||
return objects
|
|
||||||
.reduce(function(res, cur){
|
|
||||||
var o = Object.create(res)
|
|
||||||
Object.keys(cur)
|
|
||||||
.map(function(k){
|
|
||||||
Object.defineProperty(o, k,
|
|
||||||
Object.getOwnPropertyDescriptor(cur, k)) })
|
|
||||||
return o }, root) }
|
|
||||||
|
|
||||||
|
|
||||||
// Like .mixin(..) but will mixin all the methods/props/attrs directly
|
|
||||||
// (flatly) into root...
|
|
||||||
//
|
//
|
||||||
// NOTE: essentially this is just like Object.assign(..) but copies
|
// NOTE: essentially this is just like Object.assign(..) but copies
|
||||||
// properties directly rather than copying property values...
|
// properties directly rather than copying property values...
|
||||||
@ -110,6 +88,26 @@ function(root, ...objects){
|
|||||||
return root }, root) }
|
return root }, root) }
|
||||||
|
|
||||||
|
|
||||||
|
// Mix sets of methods/props/attrs into an object as prototypes...
|
||||||
|
//
|
||||||
|
// mixin(root, object, ...)
|
||||||
|
// -> root
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// This will create a new object per set of methods given and
|
||||||
|
// mixinFlat(..) the method set into this object leaving the
|
||||||
|
// original objects intact.
|
||||||
|
//
|
||||||
|
// root <-- object1_copy <-- .. <-- objectN_copy
|
||||||
|
//
|
||||||
|
var mixin =
|
||||||
|
module.mixin =
|
||||||
|
function(root, ...objects){
|
||||||
|
return objects
|
||||||
|
.reduce(function(res, cur){
|
||||||
|
return mixinFlat(Object.create(res), cur) }, root) }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// Make a JavaScrip object constructor...
|
// Make a JavaScrip object constructor...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user