Latest Articles:
Committee Members:
Alert Email
Get a short email alert whenever a new entry is published.
Confidential, secure it's piece of cake to keep uptodate.
OpenBD gains "new x.y.z()" support
CFSCRIPT has been getting a lot of attention of late, bringing it more 'language' like, allowing you do more and more without needing to drop to tags. Ideal for business logic. OpenBD already supports many great enhancements to the CFSCRIPT notation, including many Javascript directives for declaring structures/arrays using the {key:[1,2,3,5],key2:{a:b}} syntax.
Another great addition has just made its way to the nightly build which is a more Java like way of creating your objects. Instead of using CreateObject(), you can now use the new Object() syntax, in much the same way you would declare objects in Java.
In addition to this, the unofficial/official constructor for CFC's, the init() function, is also called at object creation time, if found. Which incidentally means, that the init() function no longer needs to return back "this" which is the standard pattern in CFC creation at the moment. Naturally, you can still do that with no side effects.
An example of this new operator and the permutations can be seen here:
<!--- simple cfc path --->
<cfset obj = new test()>
<!--- full cfc path --->
<cfset obj = new full.path.to.test()>
<!--- cfc path as string --->
<cfset obj = new "test"()>
<!--- full cfc path as string --->
<cfset obj = new "full.path.to.test"()>
<!--- with arguments --->
<cfset t = new test( "foo", "bar" )>
<!--- with named arguments --->
<cfset t = new test( bar: "bar", foo: "foo")>
<!--- with args passed in as argumentcollection --->
<cfset args = { bar = 2, foo = 1 }>
<cfset t = new test( argumentcollection: args )>
All the usual path searching kicks in at this point (explicit support for import x; is coming soon).
You can start playing with this new syntax now, by downloading the nightly build.
Comments (6)
Good spot, I've fixed the example. It doesn't work with java classes but that might change in the future.
Looks awesome. Two things: In the top 3 cfsets there is an additional closing parenthesis before the closing of the tag, I'm assuming that that is a typo right? Also, I've dabbled with java within cfscript and whenever I pasted java code directly into cfscript, and there was a "new obj()", I would have to rewrite the syntax to make it cfscript compatible. Will this work now with raw java code or is it specifically for creating a cfc object? I see that import is coming soon too which leads me to believe that we are heading towards true java compatibility. This would just blow the roof!!!!
Awesome, thanks!
Correct, or in the top level customtags folder, or the root folder of the webapp folder. The wonders of the infamous "hunt-a-tag" madness that is CFML!
So does this mean that to execute this statement:
<cfset obj = new test() )> The test.cfc only need reside in the local folder of the script executing the cfset statement? If so, that is cool and I have wondered from day 1 why you couldn't do that in ColdFusion... :) patrick



this is very nice, thanks!
It would be *great* to have support for java objects creation as well. Creating cfcs with java-style new and java objects with cf-style createObject('java',xxx) in our factories seems a bit silly :)