russplaysguitar / UnderscoreCF

An UnderscoreJS port for Coldfusion. Functional programming library.
http://russplaysguitar.github.com/UnderscoreCF/
MIT License
89 stars 38 forks source link

Issues with Railo (not Underscore's fault) #10

Closed jfrux closed 11 years ago

jfrux commented 11 years ago

Okay, I just posted an issue with the Railo Group about the "this" scope and whether or not I'm approprately using it lmao...

Here is my post, let me know if you think I'm just a n00b or if it should behave this way.


I have some concerns with components that implement other components potentially losing site of the "this" scope. Maybe it's just something with my code but the best way I can explain it is with pseudo-code for now. That's all I have time for. It could be 'just me' but I figured I would share in case I'm doing something wrong.

Let's say we have 1 cfc, we'll call it "utilities.cfc" which has the following code:

component {
public any function init() {
return this;
};
public any function mapper(arr,func) {
      func(do,something,now);
};

public any function doer(arr,func) {
     func(do,something,now);
};

public any function donter(arr,func) {
       func(do,something,now);
};
}

THEN, we have another CFC that uses this utilities.cfc, we'll call it 'worker.cfc' which has code like such...

component {
     public any function init() {
           variables.util = new utilities();
     }

     public any function fooer(arr) {
            util.mapper(arr,this.doerFunc);
     }

     public any function doerFunc(this,that,andthis) {
           writeDump(var=this,abort=true); //'this' now represents the "utilities.cfc" because I passed this function to the util.mapper.
     }
}

Is this normal behavior? am I just stupid? :D I mean, I assume the reason it's acting this way is because 'doerFunc' is passed as a function expression to the utilities.cfc function which now executes it under it's own scope but is this intentional? Should this work this way?

I'll try to get a real test case up as soon as I can.

Please advise.

Sincerely, Joshua F. Rountree

russplaysguitar commented 11 years ago

Hmm, yeah I had problems with Railo's "this" scope handling as well. The work-around it in Underscore.cfc was to pass in "this" as an argument to the iterator functions. I'd love to get rid of that hack, so let me know how it goes on the Railo group!

jfrux commented 11 years ago

Would you sometime be able to do me a favor...? I'd love it if you could make a branch without the "railo hack" so I can submit this entire library to them along with the unit test results so they can see all the places Railo fails with UnderscoreCF?

Would that info be evident in the tests?

russplaysguitar commented 11 years ago

Sure! You can actually see it already if you just look at the history. Version 1.x.x fails in Railo due to this issue.

russplaysguitar commented 11 years ago

See 230ced37fc1cacf0296ee9ebf11b55d12b4ed1a7 (browse it: https://github.com/russplaysguitar/UnderscoreCF/tree/230ced37fc1cacf0296ee9ebf11b55d12b4ed1a7)