mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 10:30:08 +00:00
minor tweaks...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
735ecf65fd
commit
915d67bc07
@ -1153,6 +1153,10 @@ function(base, ...objects){
|
|||||||
// mixin(obj)
|
// mixin(obj)
|
||||||
// -> obj
|
// -> obj
|
||||||
//
|
//
|
||||||
|
// mixin(mode, obj)
|
||||||
|
// mixin(obj, mode)
|
||||||
|
// -> obj
|
||||||
|
//
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
@ -1182,6 +1186,8 @@ Constructor('Mixin', {
|
|||||||
|
|
||||||
// mixin to target...
|
// mixin to target...
|
||||||
__call__: function(_, target, mode=this.mode){
|
__call__: function(_, target, mode=this.mode){
|
||||||
|
typeof(target) == typeof('str')
|
||||||
|
&& ([mode, target] = arguments)
|
||||||
return mode == 'flat' ?
|
return mode == 'flat' ?
|
||||||
mixinFlat(target, this.data)
|
mixinFlat(target, this.data)
|
||||||
: mixin(target, this.data) },
|
: mixin(target, this.data) },
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-object",
|
"name": "ig-object",
|
||||||
"version": "5.4.0",
|
"version": "5.4.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "object.js",
|
"main": "object.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -25,7 +25,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/flynx/object.js#readme",
|
"homepage": "https://github.com/flynx/object.js#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"c8": "^7.3.4",
|
"c8": "^7.3.5",
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"ig-test": "^1.4.6"
|
"ig-test": "^1.4.6"
|
||||||
}
|
}
|
||||||
|
|||||||
36
test.js
36
test.js
@ -710,6 +710,42 @@ var cases = test.Cases({
|
|||||||
assert(typeof(xx.call) == 'function', 'xx.call is a function')
|
assert(typeof(xx.call) == 'function', 'xx.call is a function')
|
||||||
assert(xx.call(null), 'xx.call(null)')
|
assert(xx.call(null), 'xx.call(null)')
|
||||||
},
|
},
|
||||||
|
mixins: function(assert){
|
||||||
|
|
||||||
|
var A = assert(object.Mixin('A', {
|
||||||
|
a: 'aaa',
|
||||||
|
}))
|
||||||
|
assert(A.data.a == 'aaa')
|
||||||
|
|
||||||
|
var B = assert(object.Mixin('B', {
|
||||||
|
b: 'bbb'
|
||||||
|
}))
|
||||||
|
assert(B.data.b == 'bbb')
|
||||||
|
|
||||||
|
var C = assert(object.Mixin('C',
|
||||||
|
A,
|
||||||
|
B,
|
||||||
|
{
|
||||||
|
get c(){
|
||||||
|
return 'ccc' },
|
||||||
|
}))
|
||||||
|
assert(C.data.a == 'aaa')
|
||||||
|
assert(C.data.b == 'bbb')
|
||||||
|
assert(C.data.c == 'ccc')
|
||||||
|
|
||||||
|
var x = assert(C({}))
|
||||||
|
|
||||||
|
assert(x.a == 'aaa')
|
||||||
|
assert(x.b == 'bbb')
|
||||||
|
assert(x.c == 'ccc')
|
||||||
|
|
||||||
|
var y = assert(C({}, 'flat'))
|
||||||
|
|
||||||
|
assert(y.a == 'aaa')
|
||||||
|
assert(y.b == 'bbb')
|
||||||
|
assert(y.c == 'ccc')
|
||||||
|
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user