mirror of
https://github.com/flynx/object.js.git
synced 2025-12-19 18:01:40 +00:00
added mixin(..) and parent(..)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a7f42d1e8c
commit
c646b938df
37
object.js
37
object.js
@ -257,6 +257,43 @@ function superMethod(cls, meth){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// super replacement...
|
||||||
|
//
|
||||||
|
// parent(meth, this)
|
||||||
|
// parent(meth, name, this)
|
||||||
|
// -> meth
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// XXX move this to object.js
|
||||||
|
var parent =
|
||||||
|
module.parent =
|
||||||
|
function(meth, name, that){
|
||||||
|
if(arguments.length == 2){
|
||||||
|
that = name
|
||||||
|
name = meth.name
|
||||||
|
}
|
||||||
|
while(!that.hasOwnProperty(name) || that[name] !== meth){
|
||||||
|
that = that.__proto__
|
||||||
|
}
|
||||||
|
return that.__proto__[name]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// XXX move this to object.js
|
||||||
|
var mixin =
|
||||||
|
module.mixin =
|
||||||
|
function(root, ...objects){
|
||||||
|
return objects
|
||||||
|
.reduce(function(res, cur){
|
||||||
|
return Object.assign(Object.create(res), cur) }, root) }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
* vim:set ts=4 sw=4 : */ return module })
|
* vim:set ts=4 sw=4 : */ return module })
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-object",
|
"name": "ig-object",
|
||||||
"version": "1.0.7",
|
"version": "1.1.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "object.js",
|
"main": "object.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user