Entries for month: October 2011

Definition of a Function vs Method

ColdFusion , Misc , Javascript No Comments »

After a recent discussion as to the correct terminology to use when referring to code written in CFCs I've decided to share my opinion so people have a general idea as to what is meant when someone is referring a function or a method in its simplest sense. 

  • A function is a piece of reuseable code that is called by name.  It can be passed data to operate on (arguments / parameters) and can optionally return a result.
  • A method (also known as a property method) is a piece of code that is called by name that is associated with an object.  A method is almost identical to a function but it's purpose is generally to operate on the data contained within the component (class).

For example, in JavaScript, methods are defined as object properties that contain a function() whose intent is to operate on the data within that object.  Whereas an example of JavaScript functions would be built in global functions such as isNaN(), alert() or user defined functions function debugLog( content ){ console.log( content ) }.

Likewise, in ColdFusion, you could probably say that UDFs (User defined functions) and the standard built in functions provided by ColdFusion are "functions" and the functions within CFCs are methods.

I'm sure people have their own opions on this but in general that's how I like to refer to functions or methods.

 

Bookmark and Share
Powered by Mango Blog. Design and Icons by N.Design Studio
RSS Feeds