removed redundant args to parent(..) + some cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-04-30 02:01:00 +03:00
parent 3eabbdbbef
commit 9fed68370b
3 changed files with 30 additions and 28 deletions

View File

@ -201,14 +201,14 @@ sources(<object>, <name>, <callback>)
-> <list> -> <list>
``` ```
Get parent method Get parent attribute value or method
``` ```
parent(<method>, <this>) parent(<prototype>, <name>)
-> <parent-method> -> <parent-value>
-> undefined -> undefined
parent(<prototype>, <name>, <this>) parent(<method>, <this>)
-> <parent-value> -> <parent-method>
-> undefined -> undefined
``` ```

View File

@ -75,13 +75,14 @@ function(obj, name, callback){
var res = [] var res = []
do { do {
if(obj.hasOwnProperty(name)){ if(obj.hasOwnProperty(name)){
res.push(obj) res.push(obj)
// handle callback... // handle callback...
stop = callback stop = callback
&& callback(obj) && callback(obj)
// stop requested by callback... // stop requested by callback...
if(stop === false || stop == 'stop'){ if(stop === true || stop == 'stop'){
return obj } } return res }
}
obj = obj.__proto__ obj = obj.__proto__
} while(obj !== null) } while(obj !== null)
return res } return res }
@ -90,7 +91,7 @@ function(obj, name, callback){
// Find the next parent attribute in the prototype chain. // Find the next parent attribute in the prototype chain.
// //
// Get parent attribute value... // Get parent attribute value...
// parent(value, name, this) // parent(proto, name)
// -> value> // -> value>
// -> undefined // -> undefined
// //
@ -108,7 +109,7 @@ function(obj, name, callback){
// //
// method: function(){ // method: function(){
// // get attribute... // // get attribute...
// var a = object.parent(X.prototype.attr, 'attr', this) // var a = object.parent(X.prototype, 'attr')
// //
// // get method... // // get method...
// var ret = object.parent(X.prototype.method, this).call(this, ...arguments) // var ret = object.parent(X.prototype.method, this).call(this, ...arguments)
@ -130,25 +131,26 @@ function(obj, name, callback){
// loops, for example, this.method deep in a chain will resolve to // loops, for example, this.method deep in a chain will resolve to
// the first .method value visible from 'this', i.e. the top most // the first .method value visible from 'this', i.e. the top most
// value and not the value visible from that particular level... // value and not the value visible from that particular level...
var parent = //
// XXX need to add a way to work with props...
var parent =
module.parent = module.parent =
function(proto, name, that){ function(proto, name){
// special case: method... // special case: method...
if(arguments.length == 2){ if(typeof(name) != typeof('str')){
var method = proto that = name
proto = that = name name = proto.name
name = method.name // get first matching source...
// skip until we get to the current method... proto = sources(that, name,
while(proto.__proto__ && proto[name] !== method){ function(obj){ return obj[name] === proto })
proto = proto.__proto__ .pop() }
} // get first source...
} var res = sources(proto, name,
// skip till next name occurrence... function(obj){ return 'stop' })
while(proto.__proto__ && !proto.hasOwnProperty(name)){ .pop()
proto = proto.__proto__ return res ?
} res.__proto__[name]
// get next value... : undefined }
return proto.__proto__[name] }
// Find the next parent method and call it... // Find the next parent method and call it...

View File

@ -1,6 +1,6 @@
{ {
"name": "ig-object", "name": "ig-object",
"version": "2.4.6", "version": "2.5.0",
"description": "", "description": "",
"main": "object.js", "main": "object.js",
"scripts": { "scripts": {