The Wayback Machine - https://web.archive.org/web/20100917060213/http://alan.blog-city.com/cfc_javascript.htm

alanwilliamson

CFML CFC Function Declaration's in Javascript

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

How about a full cfjs component by flagging it as such in a header attribute /**

  • I am a CFJS component

  • @cfjs

component = {
  • function batman(){}

}

Speaking of which will we be able to getMetaData from JavaScript files to get JSDoc information? That'd be super awesome levels of SWEET!
left by Marcel Bennett — Tuesday, 1 December 2009 9:59 PM — web site

Holy cow, I think I just passed out with excitement reading your post :) Very cool stuff!

left by Ben Nadel — Tuesday, 1 December 2009 3:18 PM — web site

Leave Comment

please note, all comments will be moderated for spam and abuse before being publicly posted.


 

Recent Cloud posts

Recent JAVA posts

Latest CFML posts


 
Site Links
Recommended Sites/Blogs

Follow javachampion on Twitter