mirror of
https://github.com/flynx/object.js.git
synced 2025-10-30 02:50:10 +00:00
found a bug...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
5a4b999382
commit
78529b667b
17
object.js
17
object.js
@ -352,6 +352,20 @@ function(obj, name, callback){
|
||||
//
|
||||
//
|
||||
// NOTE: for more docs on the callback(..) see sources(..)
|
||||
//
|
||||
// XXX BUG: passing a callback here breaks the return value at the STOP...
|
||||
// essentially this is a question of how can we return STOP and the
|
||||
// value to be returned at the same time???
|
||||
// ...ways to go:
|
||||
// - store the last return from callback(..) and if it's STOP
|
||||
// patch the last value (HACK-ish)
|
||||
// - skip the last value...
|
||||
// ...this will complicate the logic quite a bit as the user
|
||||
// will need to STOP after the last position...
|
||||
// - return STOP(value) or [STOP, value]
|
||||
// ...requires the user not to forget...
|
||||
// - ignore the callback return value...
|
||||
// ...this seems the most uniform, but this can break things...
|
||||
var values =
|
||||
module.values =
|
||||
function(obj, name, callback, props){
|
||||
@ -374,7 +388,8 @@ function(obj, name, callback, props){
|
||||
return callback(_get(obj, name), obj) }
|
||||
return c ?
|
||||
// NOTE: we do not need to handle the callback return values as
|
||||
// this is fully done in sources(..)
|
||||
// this is fully done by c(..) in sources(..)
|
||||
// XXX BUG: if this stops the last value will be the obj and not the prop...
|
||||
sources(obj, name, c)
|
||||
: sources(obj, name)
|
||||
.map(function(obj){
|
||||
|
||||
24
test.js
24
test.js
@ -651,6 +651,30 @@ var cases = test.Cases({
|
||||
assert(object.parent({}) === {}.__proto__, 'basic proto')
|
||||
assert.error('.parent(..) of anonymous function', function(){
|
||||
object.parent(function(){}, {}) })
|
||||
|
||||
// object.values(..)
|
||||
var obj = Object.create({x: 123})
|
||||
obj.x = 321
|
||||
|
||||
assert.array(
|
||||
object.values(obj, 'x', true)
|
||||
.map(function(e){ return e.value }),
|
||||
// XXX essert ignores the order here -- this should fail...
|
||||
[123, 321], '.values(.., true) ')
|
||||
|
||||
// XXX BUG: this returns the object and not the value...
|
||||
console.log('>>>>>', object.values(obj, 'x', function(){ return object.STOP }))
|
||||
// XXX BUG: this returns the object and not the prop descriptor...
|
||||
console.log('>>>>>', object.values(obj, 'x', function(){ return object.STOP }, true))
|
||||
|
||||
assert(
|
||||
object.values(obj, 'x', function(){ return object.STOP })[0] == 321,
|
||||
// XXX essert ignores the order here -- this should fail...
|
||||
'.values(.., func) ')
|
||||
assert(
|
||||
object.values(obj, 'x', function(){ return object.STOP }, true)[0].value == 321,
|
||||
// XXX essert ignores the order here -- this should fail...
|
||||
'.values(.., func, true) ')
|
||||
},
|
||||
deepKeys: function(assert){
|
||||
var a = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user