In the class below the function result() will display the value of the variable whatToDo
accordingly the functions addition
and multiplication
are called.
Condition : Here, in the below code what if whatTodo
is addition
but function addition
is only not called.
Question : How can I deal this Condition ?
class SomeClass{
let whatToDo: string;
public result(){
if ( this.whatToDo == 'additon'){
return this.whatToDo;
}
else if (this.whatToDo == 'multiplcation'){
return this.whatToDo;
}
}
public addition(){
this.whatToDo = 'addition';
//do something
}
public multiplication(){
this.whatToDo = 'multiplication';
//do something
}
}
Use case - When whatTodo
is assigned as addition
before calling addition(), so it should tell that whatToDo
is undefined
so that it can be easily differentiated that addition() is not yet called.This what I want ot achieve.
It looks like just a typo, try:
public result(){
if ( this.whatToDo == 'addition'){
return this.whatToDo;
}
else if (this.whatToDo == 'multiplication'){
return this.whatToDo;
}
You misspelled the words "additon" and "multiplcation" in your code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.