Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
As I mentioned earlier in the course I'm not a huge fan of CFScript, but for those that are, this is the video for you. ColdFusion 9 now allows you to write CFCs entirely in CFScript, no tags at all, not even a CFScript tag. In this video, we are going to take an existing CFC and show you the pure CFScript version to show you the format of the component and a method definitions as well as the Javadoc Style of defining attributes and metadata for your properties and methods. So in the Chapter4 cfcs directory, we will open Person.cfc.
This is the same CFC we used in the previous video to show you the implicit getters and setters. Sitting right next to that is PersonCFScript.cfc. This is the exact same component written in CFScript instead of ColdFusion tags. So I am going to show you these two files side-by-side. Now, the first thing you should notice is that first off, there is no open bracket cf anywhere. Second, there's no CFScript tags surrounding the component. You can start a component in CFScript by simply typing component at the top.
You can put the attributes that you would normally put on the CF Component tag and open brace, and at the bottom you have your closing brace that denotes the end of the component. In between there, you put all of your properties and functions just like you would in any other regular CFC. Here on our CF Properties, we have basically just removed the open bracket cf from the property itself. We have our name, type, hint, all the same attributes you would use, but where we start to see differences is in the function definitions. If you take a look here, I have my init function.
So I have first off the access, whether it's public, private, or remote. The keyword function and then the name of that function and inside the parenthesis, I have a comma- separated list of all of my arguments. They have their type followed by the name and if it has a default value, you put equals and its default value. If it does not have a default value, you simply leave that off. If you want to make an argument required, then you type required in front of it. So I have a required string, FirstName with no default value.
I am going to remove that and down here on my getters and setters for the state, they will be exactly the same. A public function, setState, and it takes one argument called state, which is a string. Now, where things really differ is how you go about setting the metadata on your functions. Because ColdFusion allows you to have a whole bunch of metadata about functions, there's no good way to put them as attributes inside of this declaration. So what will you do is directly before your function definition you put a /** and then **/ again to close the Javadoc comment for this particular function.
The first lines inside that comment are the hint for the function. So here you can see it initializes any data in the object. Over here in my standards tag base when you will see the same hint, "initializes any data in the object." Then you can determine the output and return type by doing the @output, true or false, @return type and then the type that needs to be returned. Then for each of the arguments, you can put the @ symbol, the argument name and then the hint for that particular item.
So to show you that these are functionally equivalent, we are going to use the ColdFusion component browser. So we will switch over to Safari and we are going to go to localhost:8500/CFIDE/ componentutils/componentdoc.cfm. It's going to ask us for RDS password and here we can see all of our components on the server. In this case, we want to look at the Chapter4.cfcs and here I have my Person and PersonCFScript.
If I click on Person, we can see I have my path correct here. I have my hint on the CF Component tag. I have all of my properties. I only defined a hint on the Firstname property and on my init method, I can see the two line hint that I typed as well as each of the hints on the individual arguments. Now, if I click on PersonCFScript, they are almost exactly the same. They are not the same, because my PersonCFScript has accessors="true" on it. Let's go back over here and remove that and then reload this page and now they look exactly the same.
All my implicit getters and setters have now be removed. We can see the same hint at the top, the same hint on the properties. If I scroll down here, I can see the same hint on my init method and all the same hints on my arguments. While CFScript isn't my thing, it may very well be yours and this is a fantastic way to be able to write all of your components in pure CFScript. As far as I can tell, there are no performance improvements from using one over the other, however, if you're coming from a Java or PHP or other languages that only offers a script-based syntax, this will make it much easier for you to get involve with ColdFusion or potentially convince those people in your office that are still holding out migrating to move over to ColdFusion.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 92453 Viewers
82 Video lessons · 104134 Viewers
71 Video lessons · 75588 Viewers
56 Video lessons · 106961 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.