Adam Cameron
// Person.cfc
component {
function init(firstName, lastName) {
variables.firstName = arguments.firstName
variables.lastName = arguments.lastName
}
static function createFromArray(nameParts) {
return new Person(nameParts[1], nameParts[2])
}
}
Note the explicit reference to Person in createFromArray.
I was rather expecting to be able to go new this or new self or something there. Neither worked... what - if anything - is the CFML equiv of that?
Full disclosure: I have not googled much, and don't want ppl to do my googling for me... it's pretty much a throw-away question. So if someone knows... I'd appreciate the knowledge share. I don't expect anyone to do any of their own research to work it out though.
Thanks!Tomy Saman
05/01/2023, 5:45 AMfunction init(firstName, lastName) {
variables.firstName = arguments.firstName
variables.lastName = arguments.lastName
return this;
}
function createFromArray(nameParts) {
return init(nameParts[1], nameParts[2])
}
Or specify the classPath of this CFC when creating a instance in createFromArray():
function createFromArray(nameParts) {
return createObject("component", "path.to.this.cfc").init(nameParts[1], nameParts[2])
}