tracker issue : CF-4205196

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

Implement Spread Operator

| View in Tracker

Status/Resolution/Reason: To Fix//Investigate

Reporter/Name(from Bugbase): Abram A. / ()

Created: 09/09/2019

Components: Language

Versions: 2018

Failure Type:

Found In Build/Fixed In Build: N/A /

Priority/Frequency: Normal /

Locale/System: / Other

Vote Count: 3

The Spread operator is super convenient in the JavaScript world and would be a great addition to the modern trend of functions/syntaxes being adopted by cfscript.

I would suggest implementing it in the same way as JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax 

The return from a spread operation would be a new array or struct containing the items that were spread out.  Would allow for much cleaner functional programming style where avoiding mutating data is key.

Merging objects is another benefit:

var obj1 = { foo: 'bar', x: 42 };
var obj2 = { foo: 'baz', y: 13 };

var mergedObj = { ...obj1, ...obj2 };
// Object { foo: "baz", x: 42, y: 13 }

Oh, and another, converting a string into array:

var myArray = [..."12345"];
// ["1", "2", "3", "4", "5"]

As a side effect, this could eliminate the need to do things like 

myFunction( argumentCollection=args )
and instead you'd be able to do 

myFunction( ...args )

Attachments:

Comments: