jupiterjs/jquerymx — Issue #87: proxy method not properly passing array return parameters
Author: dimaf
Created: 2011-11-08 22:22:55+00:00
State: open

Hi,
I think there is a problem with proxy method. If I call proxy with multiple callback functions that return array back, that array is not properly passed to the next callback function. Here is short example that demonstrates the problem

```javascript

test:function (){
this.run(['a','b','c'],this.proxy(["call1","call2"]));
},
run:function(arr,callback){
callback(arr);
},
call1:function(arr){
steal.dev.log("array length: "+arr.length);
return arr;
},
call2:function(arr){
steal.dev.log("array length: "+arr.length);
return arr;
},

```

If you run "test" function
The output is
steal.js INFO: array length: 3
steal.js INFO: array length: 1

Where I'd expect to see in both cases Length 3.

I tried to change in class.js

```javascript
if ( f < length - 1 ) {
cur = !isArray(cur) || cur._use_call ? [cur] : cur
}

```

to

```javascript
if ( f < length - 1 ) {
cur = [cur];
}

```
That fixed the issue and everything still seems to work.
Are there any special reasons for that !isArray(cur) || cur._use_call condition?
after all apply always wants to have a array of arguments.

This problem is also now causing Model to fail when using following config for ajax call
....
success: this.proxy(['models',success]),
...
I saw, since few days this line is comented out in model.js

//res._use_call = true; //so we don't call next function with all of these

Regards,
Dmytro