artknight
02/12/2024, 7:08 PM//primary.cfc
component {
function init(){
variables.sub = new $sub(); //new this$sub(); //new primary$sub();
return this;
}
}
component name="sub" {
function init(){ return this; }
}Robert Zehnder
02/12/2024, 8:09 PMsub.cfcvariables.sub = new sub()Robert Zehnder
02/12/2024, 8:11 PMRobert Zehnder
02/12/2024, 8:12 PMartknight
02/12/2024, 8:14 PMRobert Zehnder
02/12/2024, 8:36 PMartknight
02/12/2024, 8:39 PMAdam Cameron
artknight
02/12/2024, 9:24 PMnew component$sub() worksAdam Cameron
// Parent.cfc
component {
function init() {
writeOutput("Main init<br>");
variables.sub = new Parent$Sub();
}
function getSub() {
return variables.sub;
}
}
component name="Sub" {
function init() {
writeOutput("Sub init<br>");
}
}
<!--- test.cfm --->
<cfscript>
parent = new Parent()
sub = parent.getSub()
writeDump([
sub=sub,
metadata = getMetaData(sub)
])
</cfscript>Adam Cameron
Robert Zehnder
02/12/2024, 9:35 PMAdam Cameron
Adam Cameron
Adam Cameron
artknight
02/13/2024, 12:59 PMAdam Cameron
this in CFML is a reference to an object. Whereas Parent$Sub is a reference to a component.
So using this in that context doesn't make any sense.Adam Cameron
Adam Cameron
anotherOne = new this() from within a CFC to create another instance of the same CFC can it (suddenly I am unsure, ha!)artknight
02/13/2024, 2:30 PMartknight
02/13/2024, 2:33 PMAdam Cameron
I would argueRight. So despite the fact I just explained why that is off the mark, you'd still argue it. Cool. Um... file system references will still be case-sensitive on case-sensitive file systems. And last time I checked (which admittedly was ages ago... like over a decade), CFC paths / names are used for the file system access of same. But we don't need to conjecturize here. You have yer code and your computer, so you could... check?
artknight
02/13/2024, 4:07 PMAdam Cameron
Robert Zehnder
02/13/2024, 4:41 PMartknight
02/13/2024, 4:45 PMdswitzer
02/15/2024, 1:11 PMAdam Cameron
that it's not usable outside of the component.Indeed. I await to see how ppl abuse this feature, given the subclasses are accessible from the calling code. I guess the benefit over just "another CFC in the same package" is that the sub has access to the private stuff in the main class.