is it expected that in a fat arrow function being ...
# adobe
r
is it expected that in a fat arrow function being run inside a function, that it cannot access the local scope?
r
Have a simple example?
Copy code
<cfscript>
    a = "";
    myList = "ray,ben,brad,luis";
    myList.listToArray().each((ele) => {
        a = a.listAppend(ele)
    });
    writeDump(a);
</cfscript>
r
no, use it in a function
👍 1
r
that works, but it may not be a 1:1 comparison
lemme retry
r
Copy code
function goo() {
	local.arr = [ "ray", "camden" ];
	local.moo = "zoo";

	local.arr.each(a => {
		writeoutput("a is #a#<p>");
		writeoutput("moo is #local.moo#");
	});
}

goo();
a
It does not read the
local.
scoped variables of the parent.
💯 1
local.
is only for the current function context.
r
whats odd is, i CAN get to it if i drop
local
r
Copy code
<cfscript>
    a = "";
    myList = "ray,ben,brad,luis";
    
    buildList(myList);
    
    function buildList(inp){
        inp.listToArray().each((ele) => {
            a = a.listAppend(ele);
        });
    }
    
    writeDump(a);
</cfscript>
a
I always disliked the
local.
prefix but had some code that used it so did bump into this.
r
as long as it doesnt leak im ok
going to test that now
👍 1
a
With a
var
scope in the parent context it should be fine.
r
it does NOT leak
👍 1
a
FYI - for Lucee you have to do
arr.each((a) => {
ACF works with that or
arr.each(a => {
🤘 1
r
i have gotten in the habit of trying to make things as portable as possible since i switch engines a bit
👍 1
r
eh, this is for an open sourcre project and if folks want that, they can send me a pr 😉
🍴 1
r
word
r
r
you will be back to doing CF before you know it 😛
r
No. Except for this. Honest.
❤️ 1
😈 1
r
This looks like it might have been the error you received?
r
aye
r
ok, yeah, doesn't like the
local
in the fat arrowed func
Copy code
function start(){
        local.a = "";
        local.myList = "ray,ben,brad,luis";
        
        local.myList.listToArray().each((ele) => {
            local.a = local.a.listAppend(ele);
        });
        
        writeDump(local.a);
    }

    
    start();
a
The
local.
scope was always an odd CFML quirk as you don't see it in other languages. It always felt clunky.
r
agreed
r
on one hand, when i did more CF, i liked EXPLICITELY seeing this was a locally scopped var versus an arguments. on the other hand, if i cant tell then my function may be poorly written 😉
a
Ha 🙂 My train of thought was that if I couldn't see where a variable came from then my function was way too many lines
s
"local" inside arrow functions works as expected? it's local to within the arrow function/function. So it's not like "local" isn't acceptable/not working inside arrow functions
r
that may be a good point there, there may be a new local inside the arrow func
s
yeah, there definitely is
m
We just did a MASSIVE rehaul of this in 2025. Not sure its in the current drop, but we improved performance by like... a metric llama load. Which is a lot.