tracker issue : CF-3495357

select a category, or use search below
(searches all categories and all time range)
Title:

Closures and outer arguments have no scope

| View in Tracker

Status/Resolution/Reason: Closed/Deferred/NotWorthEffort

Reporter/Name(from Bugbase): Andrew Scott / Andrew Scott (Andrew Scott)

Created: 02/04/2013

Components: Language, Closures

Versions: 10.0

Failure Type: Enhancement Request

Found In Build/Fixed In Build: Final /

Priority/Frequency: Minor / Some users will encounter

Locale/System: English / Platforms All

Vote Count: 2

Problem Description:

When looking at the below code, the outer arguments have no scope, in Railo they use the variables scope which I believe is confusing, But it is also confusing to not have a scope as one is always taught that we should scope our variables.

function helloTranslator(String helloWord) 
    { 
        return function(String name) 
            { 
                return "#helloWord#, #name#"; 
             }; 
    } 



Steps to Reproduce:

Actual Result:

Expected Result:

Any Workarounds:

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3495357

External Customer Info:
External Company:  
External Customer Name: ascott67
External Customer Email:  
External Test Config: My Hardware and Environment details:

Attachments:

Comments:

Why is this not worth the effort, this is how closures are supposed to work....
Comment by External U.
16391 | October 01, 2013 10:17:31 PM GMT
Yeah, not a great answer there from Adobe. How about you at least explain why you can't be arsed doing it? FWIW, I agree with Andrew that this should be sorted out. -- Adam
Vote by External U.
16395 | October 07, 2013 08:13:57 AM GMT
+1 - Please add "caller" scope in cfscript2.0 closures. (edited: changed "owner" to "caller" - to mimic Custom Tags)
Vote by Aaron N.
16396 | May 24, 2017 06:10:49 AM GMT
Hi Adobe, There should be a cleaner way to reference the owner function. How about a formal "owner" scope? <cfscript> function f(index) { var myArray = ["foo","bar"]; var becauseBug = ARGUMENTS.index; return myArray.map(function(element, index, array) { return element & becauseBug;//how about owner.index? }); } writeDump(f(4)); </cfscript> Instead of "becauseBug", how about owner.index? Thanks!, -Aaron
Comment by Aaron N.
16392 | May 24, 2017 06:32:34 AM GMT
NotWorthEffort? Sigh. We should be able to scope the references to a closure's parent function's arguments.
Comment by Aaron N.
16393 | December 21, 2017 10:47:12 PM GMT
Hi Adobe, How about letting the following not throw an exception?: <cfscript> function f(myArg) { var myArray = ["foo"]; myArray.each(function() { var bla = ARGUMENTS.myArg;//sets var to 'hello' }); } f("hello"); </cfscript> Basically, allowing arguments scope, within a closure, to reference the outer function's argument's scope if closure doesn't have an argument w/ the same name. Thanks!, -Aaron
Comment by Aaron N.
16394 | December 21, 2017 10:56:37 PM GMT
WorthTheEffort
Comment by Aaron N.
27591 | April 18, 2018 10:23:15 AM GMT
Even an explanation is NotWorthEffort :/
Comment by Aaron N.
27592 | April 18, 2018 10:29:39 AM GMT
Edit: There should be a cleaner way to reference the owner function. How about a formal "owner" scope? Should be: There should be a cleaner way to reference the owner function. How about a formal "caller" scope? Reason: The 'caller' scope has precedence in Custom Tags, so IMO "caller" would be better than "owner". Thanks!, -Aaron
Comment by Aaron N.
29000 | June 05, 2018 07:40:03 PM GMT