From c646b938df3241333a1e4bf99187cea8b15487ce Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 24 Dec 2018 21:20:38 +0300 Subject: [PATCH] added mixin(..) and parent(..) Signed-off-by: Alex A. Naanou --- object.js | 37 +++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/object.js b/object.js index 61f8086..f15268d 100755 --- a/object.js +++ b/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 }) diff --git a/package.json b/package.json index af13566..1acfe27 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-object", - "version": "1.0.7", + "version": "1.1.0", "description": "", "main": "object.js", "scripts": {