I have this code: ```// Person.cfc component { ...
# cfml-beginners
a
I have this code:
Copy code
// 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!
t
I think there is no such implementation in CFML? There are some work-around, such as making init() returns "this", then in createFromArray() just call "init(var1, var2)"
Copy code
function 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():
Copy code
function createFromArray(nameParts) {
        return createObject("component", "path.to.this.cfc").init(nameParts[1], nameParts[2])
    }
👍 1