This is proper Typescript (or ES6 if you ignore the static typing):
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
var greeter = new Greeter("world");
console.log( greeter.greet() ); //Hello world
But the following creates Hello undefined
, how would you rewrite this in a way it would work? And, if that's not possible, what would be the alternative to achieve this?
I'm looking into passing variables directly to functions.
class Greeter {
greet(greeting: string) {
return "Hello, " + this.greeting;
}
}
var greeter = new Greeter();
console.log( greeter.greet("world") ); //Hello undefined
UPDATE:
I'm referring to PHP like class usage like:
class Greeter {
public function greet($greeting){
return $greeting;
}
}