Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OOP under cfscript

Status
Not open for further replies.

Krogh

Programmer
Aug 16, 2001
22
CH
Hi all,

i was trying to create some &quot;objects&quot; under <cfscript> to see if cfscript supported it.. and i saw the same way than javascript doesn't work, for exemple :

function createDomNode(name,content) {
this.name = name;
this.content = content;
this.type = &quot;&quot;;
this.parentNode = null;
this.childrenCount = 0;
this.childrenNode = StructNew();
this.attributesContent = StructNew();
this.lastchild = lastchild;
this.children = children;
this.parent = parent;
this.new_child = new_child;
this.getattr = getattr;
this.setattr = setattr;
this.attributes = attributes;
return this;
}

this kind of script doesn't work cause coldfusion does not handle &quot;this&quot; variable. Is there any way to make it working ?

thanks..
 
This won't work, because ColdFusion is not an object-oriented language. If you want to return a structure, why not do this (not tested):
Code:
function createDomNode(name,content) {

ThisObj = StructNew();
ThisObj.name     = name;
ThisObj.content     = content;
ThisObj.type     = &quot;&quot;;
ThisObj.parentNode     = 'null';
ThisObj.childrenCount    = 0;
ThisObj.childrenNode    = StructNew();
ThisObj.attributesContent    = StructNew();
ThisObj.lastchild    = lastchild;
ThisObj.children    = children;
ThisObj.parent    = parent;
ThisObj.new_child    = new_child;
ThisObj.getattr    = getattr;
ThisObj.setattr    = setattr;
ThisObj.attributes    = attributes;

return ThisObj;
}

Notice:

ThisObj.childrenNode and ThisObj.attributesContent will themselves contain structures.

I changed this line:

ThisObj.parentNode = 'null';

You can't set something to just NULL in CF, since CF has no understanding of NULL. You can either set it to a blank variable using &quot;&quot;, or to a 0, or whatever else you want.

Also, all of the variable assignments must be valid; I don't know exactly what your thinking is since I don't know how you're approaching this, either from an OOP background or as a beginner to programming/scripting in general.

-Tek
 
Thanks.. i'll try this way..

anyway i saw that there's a way to handle objects under cf under mx.. (cf. .. but i think i'll wait for my MX upgrade before handling objects
 
CFObjects has been around for a bit, but in my opinion, it unecessarily complicates ColdFusion, which was made to be a tag-based language, not an OOP language. Too much overhead is incurred the more you try to encapsulate all of its functionality in objects. After all of that, you still aren't left with a true OOP language. I'd rather stick to C++ and Java when I'm in the mood for OOP; after all, these are true OOP languages!

-Tek
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top