mirror of
https://github.com/flynx/object.js.git
synced 2025-10-30 02:50:10 +00:00
removed redundant args to parent(..) + some cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
3eabbdbbef
commit
9fed68370b
10
README.md
10
README.md
@ -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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
42
object.js
42
object.js
@ -80,8 +80,9 @@ function(obj, name, 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...
|
||||||
|
//
|
||||||
|
// XXX need to add a way to work with props...
|
||||||
var parent =
|
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...
|
||||||
|
|||||||
@ -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": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user