ColdFusion structs Direct Assignment vs object literal notation.

Posted by Tom Hubbard on Stack Overflow See other posts from Stack Overflow or by Tom Hubbard
Published on 2010-03-24T10:54:50Z Indexed on 2010/03/24 11:43 UTC
Read the original article Hit count: 447

Filed under:
|

The newer versions of ColdFusion (I believe CF 8 and 9) allow you to create structs with object literal notation similar to JSON.

My question is, are there specific benefits (execution efficiency maybe) to using object literal notation over individual assignments for data that is essentially static?

For example:

With individual assignments you would do something like this:

var user = {};
user.Fname = "MyFirstnam";
user.Lname = "MyLastName";
user.titles = [];
ArrayAppend(user.titles,'Mr');
ArrayAppend(user.titles,'Dr.');

Whereas with object literals you would do something like.

var user = {Fname = "MyFirstnam",
            Lname = "MyLastName",
            titles = ['Mr','Dr']};

Now this limited example is admittedly simple, but if titles was an array of structures (Say an array of addresses), the literal notation becomes awkward to work with.

© Stack Overflow or respective owner

Related posts about coldfusion

Related posts about cfml