Can I convert this class definition to a constructor function while still using TypeScript?
class Animal {
constructor(public name: string, public energy: string) {}
}
Can I convert this class definition to a constructor function while still using TypeScript?
class Animal {
constructor(public name: string, public energy: string) {}
}
You could have a function that returns a new animal. This doesn't have to be part of a class, since you can have stand alone functions in TypeScript.
function CreateAnimal(name: string, energy: string): Animal
{
return new Animal(name, energy)
}