Here you can see that the object properties have been added without directly referencing the property names when applying the variables. This is because the variable names actually directly match the names of the properties being added.
Compare this to the older ES5 syntax, when you had to define the property names with the variables:
If, in ES6, the variable name differed for any of the properties, you would of course still need to define the property reference:
In the above example, the
bird variables still match the property names. However, we have a
pussycat variable for the
cat property, and so we need to explicitly define the property name.
Let’s consider this in a CFML context.
I think it would be amazing to have the same functionality when adding values into a CFML struct:
How about adding shorthand references in when sending argument values into a function?
I’ve created a very basic method in the following example with three argument values:
CFML functions already let you send in arguments without directly naming the property, but those depend on the values matching the order of the expected arguments within the function.
In the above example we are sending
from and then
message, but the function would automatically apply the
from value to the
message argument and the
message value to the
Ideally I’d love all future CFML engines to be able to determine which variable is assigned to which argument based upon the variable name matching the argument name.
This situation would most likely help to ensure that any non-attributed arguments have the correct default values set and validation within the methods to handle data payloads and consistency of incoming parameters, which would rely on the developer to implement.
The function implementation might be a little bit of a stretch, but struct property shorthand should be relatively easy to implement (I would assume).