diff --git a/README.md b/README.md index c734be8..cf40ed9 100755 --- a/README.md +++ b/README.md @@ -208,6 +208,14 @@ parent(, , ) -> ``` +Get parent method and call it +``` +parentCall(, ) +parentCall(, , ) + -> +``` + + Mixin objects into a prototype chain ``` mixin(, , ...) diff --git a/object.js b/object.js index ffc1484..73b3b39 100755 --- a/object.js +++ b/object.js @@ -88,9 +88,9 @@ function(obj, name, callback){ // Find the next parent method in the prototype chain. // -// parent(meth, this) -// parent(meth, name, this) -// -> meth +// parent(, ) +// parent(, , ) +// -> // // // NOTE: there are cases where method.name is not set, so a name can be @@ -112,6 +112,26 @@ function(method, name, that){ return that.__proto__[name] } +// Find the next parent method and call it... +// +// parentCall(, , ...) +// parentCall(, , this>, ...) +// -> +// +// NOTE: this is just like parent(..) but will call the retrieved method, +// essentially this is a shorthand to: +// parent(method, name, this).call(this, ...) +// or: +// parent(method, this).call(this, ...) +// NOTE: for more docs see parent(..) +var parentCall = +module.parentCall = +function(method, name, that, ...args){ + return typeof(name) == typeof('str') ? + parent(method, name, that).call(that, ...args) + : parent(method, that).call(that, ...args) } + + //--------------------------------------------------------------------- @@ -182,9 +202,11 @@ function(root, ...objects){ // var O = function(){} // // new is optional... // var o = new makeRawInstance(null, O) -// -// XXX Q: should .__new__(..) be a class method??? -// ...in a prototype model I'm not sure... +// NOTE: .__new__(..) is intentionaly an instance method (contary to +// Python) this is done because there are no classes in JS and +// adding and instance constructor as a class method would create +// unneccessary restrictions both on the "class" object and the +// instance... var makeRawInstance = module.makeRawInstance = function(context, constructor, ...args){ diff --git a/package.json b/package.json index dd28dd9..cbaef68 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-object", - "version": "2.4.0", + "version": "2.4.1", "description": "", "main": "object.js", "scripts": {