alanwilliamson
The last few days I have been working on having the ability of declaring pure Javascript functions and making them available as first class, top-level, citizens in the CFML world.
Setting up a separate CFC can be done using the following:
<cfcomponent> <cfjs> function myMethod( param1, param2 ) { return $cf.getTickCount(); }; </cfjs> </cfcomponent>
Note that you can mix CFSCRIPT, Javascript and CFML in the one CFML/CFC file. Each one can declare a top-level function and you can use whatever language you feel works best for you for that particular method.
From there on in, you can simply declare the CFC as normal and use without any problems.
<cfset cfc = CreateObject("component","cfcinjs")> <cfset x = cfc.myMethod( 1, 2 )>
We can now extend this principal and look to using the CFC in defining Application.cfc code. For example, we can now create a CFC that is subclassed by Application.cfc with all the necessary methods implemented using Javascript.
<cfcomponent> <cfjs> function onApplicationStart() { $cf.print( "onApplicationStart.cfc" ); }; </cfjs> </cfcomponent>
This is pretty darn sweet. Now you can define your CFC's in whatever language you want, and still expose it as pure CFML to those that wish to use it.
In addition to this change, I've made some significant performance gains, and in my tests, the overhead of running a CFC in Javascript and CFML is negligible.
The performance gains has been a huge boost, particularly when I load the JQuery library at the server-side and have it perform server-side DOM processing. That, I have to confess, even impressed me.
Still got some of the rough edges to polish off, but we are getting close to a proper beta release. Expect a code drop in the next day or two.
Comments
please note, all comments will be moderated for spam and abuse before being publicly posted.
Article Details
- Published:
2:12 PM GMT, Tuesday, 1 December 2009 - Categories:
Technical CFML - Tags:
cfml javascript cfscript java openbd - Comments:
2 left; add comment
Related Articles
Article Archives
How about a full cfjs component by flagging it as such in a header attribute /**
I am a CFJS component
@cfjs
function batman(){}
Holy cow, I think I just passed out with excitement reading your post :) Very cool stuff!