mirror of
https://github.com/flynx/object.js.git
synced 2025-10-30 19:10:11 +00:00
added Mixin.* static methods...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
fe8f969058
commit
6b8e46d302
24
object.js
24
object.js
@ -1182,9 +1182,23 @@ function(base, ...objects){
|
|||||||
//
|
//
|
||||||
// NOTE: the constructor will allways create a new .data object but will
|
// NOTE: the constructor will allways create a new .data object but will
|
||||||
// not do a deep copy into it -- see mixin(..) / mixinFlat(..)
|
// not do a deep copy into it -- see mixin(..) / mixinFlat(..)
|
||||||
|
//
|
||||||
|
// XXX should this move to its own modue???
|
||||||
var Mixin =
|
var Mixin =
|
||||||
module.Mixin =
|
module.Mixin =
|
||||||
Constructor('Mixin', {
|
Constructor('Mixin', {
|
||||||
|
// static methods...
|
||||||
|
// XXX should we add the above mixin funcs as static methods here???
|
||||||
|
// ...not sure yet...
|
||||||
|
// XXX if this proves usefull should we chose one or keep both locations???
|
||||||
|
// XXX EXPERIMENTAL...
|
||||||
|
mixin,
|
||||||
|
mixinFlat,
|
||||||
|
mixout,
|
||||||
|
mixins,
|
||||||
|
hasMixin,
|
||||||
|
|
||||||
|
}, {
|
||||||
name: null,
|
name: null,
|
||||||
|
|
||||||
// mixin data...
|
// mixin data...
|
||||||
@ -1200,17 +1214,17 @@ Constructor('Mixin', {
|
|||||||
// base API...
|
// base API...
|
||||||
//
|
//
|
||||||
isMixed: function(target){
|
isMixed: function(target){
|
||||||
return hasMixin(target, this.data) },
|
return this.constructor.hasMixin(target, this.data) },
|
||||||
mixout: function(target){
|
mixout: function(target){
|
||||||
return mixout(target, this.data) },
|
return this.constructor.mixout(target, this.data) },
|
||||||
|
|
||||||
// mix into target...
|
// mix into target...
|
||||||
__call__: function(_, target, mode=this.mode){
|
__call__: function(_, target, mode=this.mode){
|
||||||
typeof(target) == typeof('str')
|
typeof(target) == typeof('str')
|
||||||
&& ([_, mode, target] = arguments)
|
&& ([_, mode, target] = arguments)
|
||||||
return mode == 'flat' ?
|
return mode == 'flat' ?
|
||||||
mixinFlat(target, this.data)
|
this.constructor.mixinFlat(target, this.data)
|
||||||
: mixin(target, this.data) },
|
: this.constructor.mixin(target, this.data) },
|
||||||
|
|
||||||
__init__: function(name, ...data){
|
__init__: function(name, ...data){
|
||||||
// Mixin(name, mode, ...) -- handle default mode...
|
// Mixin(name, mode, ...) -- handle default mode...
|
||||||
@ -1224,7 +1238,7 @@ Constructor('Mixin', {
|
|||||||
// explicitly overwritten...
|
// explicitly overwritten...
|
||||||
Object.defineProperty(this, 'name', { value: name })
|
Object.defineProperty(this, 'name', { value: name })
|
||||||
// create/merge .data...
|
// create/merge .data...
|
||||||
this.data = mixinFlat({},
|
this.data = this.constructor.mixinFlat({},
|
||||||
...data.map(function(e){
|
...data.map(function(e){
|
||||||
// handle bare objects and mixins differently...
|
// handle bare objects and mixins differently...
|
||||||
return e instanceof Mixin ?
|
return e instanceof Mixin ?
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-object",
|
"name": "ig-object",
|
||||||
"version": "5.4.4",
|
"version": "5.4.5",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "object.js",
|
"main": "object.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user