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