mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 18:40:08 +00:00
bugfix... (took so long because of motivation issues)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9c9622e999
commit
5a9d977c4e
@ -571,7 +571,7 @@ sources(<object>, <name>, <callback>)
|
|||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
callback(<source>)
|
callback(<source>, <index>)
|
||||||
-> STOP
|
-> STOP
|
||||||
-> STOP(<value>)
|
-> STOP(<value>)
|
||||||
-> undefined
|
-> undefined
|
||||||
@ -619,7 +619,7 @@ values(<object>, <name>, <callback>)
|
|||||||
```
|
```
|
||||||
|
|
||||||
```
|
```
|
||||||
callback(<value>, <source>)
|
callback(<value>, <source>, <index>)
|
||||||
-> STOP
|
-> STOP
|
||||||
-> undefined
|
-> undefined
|
||||||
-> <value>
|
-> <value>
|
||||||
|
|||||||
42
object.js
42
object.js
@ -329,7 +329,7 @@ BOOTSTRAP(function(){
|
|||||||
// -> list
|
// -> list
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// callback(obj)
|
// callback(obj, i)
|
||||||
// -> STOP
|
// -> STOP
|
||||||
// -> STOP(value)
|
// -> STOP(value)
|
||||||
// -> ..
|
// -> ..
|
||||||
@ -366,6 +366,7 @@ function(obj, name, callback){
|
|||||||
callback = name
|
callback = name
|
||||||
name = undefined
|
name = undefined
|
||||||
}
|
}
|
||||||
|
var i = 0
|
||||||
var o
|
var o
|
||||||
var res = []
|
var res = []
|
||||||
while(obj != null){
|
while(obj != null){
|
||||||
@ -375,7 +376,7 @@ function(obj, name, callback){
|
|||||||
|| (name == '__call__' && typeof(obj) == 'function')){
|
|| (name == '__call__' && typeof(obj) == 'function')){
|
||||||
// handle callback...
|
// handle callback...
|
||||||
o = callback
|
o = callback
|
||||||
&& callback(obj)
|
&& callback(obj, i++)
|
||||||
// manage results...
|
// manage results...
|
||||||
res.push(
|
res.push(
|
||||||
(o === undefined || o === module.STOP) ?
|
(o === undefined || o === module.STOP) ?
|
||||||
@ -435,9 +436,9 @@ function(obj, name, callback, props){
|
|||||||
: obj[name] }
|
: obj[name] }
|
||||||
// wrap the callback if given...
|
// wrap the callback if given...
|
||||||
var c = typeof(callback) == 'function'
|
var c = typeof(callback) == 'function'
|
||||||
&& function(obj){
|
&& function(obj, i){
|
||||||
var val = _get(obj, name)
|
var val = _get(obj, name)
|
||||||
var res = callback(val, obj)
|
var res = callback(val, obj, i)
|
||||||
return res === module.STOP ?
|
return res === module.STOP ?
|
||||||
// wrap the expected stop result if the user did not do it...
|
// wrap the expected stop result if the user did not do it...
|
||||||
module.STOP(val)
|
module.STOP(val)
|
||||||
@ -514,12 +515,12 @@ function(obj, name, callback, props){
|
|||||||
// and to the method after the match.
|
// and to the method after the match.
|
||||||
// NOTE: this is super(..) replacement, usable in any context without
|
// NOTE: this is super(..) replacement, usable in any context without
|
||||||
// restriction -- super(..) is restricted to class methods only...
|
// restriction -- super(..) is restricted to class methods only...
|
||||||
//
|
// NOTE: contrary to sources(..) in the .__call__ case, this will skip
|
||||||
// XXX BUG: the two flows with parent(proto.__call__, ..) and
|
// the base callable instance, this will make both the following
|
||||||
// parent(proto, '__call__', ..) yeild different results...
|
// cases identical:
|
||||||
// ...this appears to affect only the .__call__(..) method...
|
// parent(C.prototype.__call__, obj)
|
||||||
// the problem seems to be that we are getting the first non-match
|
// and:
|
||||||
// when we want the first match after current...
|
// parent(C.prototype, '__call__')
|
||||||
var parent =
|
var parent =
|
||||||
module.parent =
|
module.parent =
|
||||||
function(proto, name){
|
function(proto, name){
|
||||||
@ -535,15 +536,21 @@ function(proto, name){
|
|||||||
throw new Error('parent(..): need a method with non-empty .name') }
|
throw new Error('parent(..): need a method with non-empty .name') }
|
||||||
// get first matching source...
|
// get first matching source...
|
||||||
proto = sources(that, name,
|
proto = sources(that, name,
|
||||||
function(obj){
|
function(obj, i){
|
||||||
return obj[name] === proto
|
// NOTE: the .hasOwnProperty(..) test is here so as
|
||||||
|
// to skip the base callable when searching for
|
||||||
|
// .__call__ that is returned as a special case
|
||||||
|
// by sourcei(..) and this should have no effect
|
||||||
|
// or other cases...
|
||||||
|
// NOTE: this will only skip the root callable...
|
||||||
|
return (i > 0 || obj.hasOwnProperty(name))
|
||||||
|
&& obj[name] === proto
|
||||||
&& module.STOP })
|
&& module.STOP })
|
||||||
.pop() }
|
.pop() }
|
||||||
// get first source...
|
// get first source...
|
||||||
var c = 0
|
|
||||||
var res = sources(proto, name,
|
var res = sources(proto, name,
|
||||||
function(obj){
|
function(obj, i){
|
||||||
return c++ == 1
|
return i == 1
|
||||||
&& module.STOP })
|
&& module.STOP })
|
||||||
.pop()
|
.pop()
|
||||||
return !res ?
|
return !res ?
|
||||||
@ -564,10 +571,9 @@ var parentProperty =
|
|||||||
module.parentProperty =
|
module.parentProperty =
|
||||||
function(proto, name){
|
function(proto, name){
|
||||||
// get second source...
|
// get second source...
|
||||||
var c = 0
|
|
||||||
var res = sources(proto, name,
|
var res = sources(proto, name,
|
||||||
function(obj){
|
function(obj, i){
|
||||||
return c++ == 1
|
return i == 1
|
||||||
&& module.STOP })
|
&& module.STOP })
|
||||||
.pop()
|
.pop()
|
||||||
return res ?
|
return res ?
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-object",
|
"name": "ig-object",
|
||||||
"version": "5.4.15",
|
"version": "5.4.16",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "object.js",
|
"main": "object.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user