it's time to translate "pizza" (yet again).
TRANSLATED:
if we want to make a new term class for "pizza", we could write it all out again. but that's a lot of work.
it's EASIER if we make a class that can become either the "pasta" or "pizza" term!
store the string you want to bite.
class StringTerm extends Term {
constructor(string) {
super()
this.string = string
}
//...
}
then use it in each of your methods, instead of the HARDCODED "pasta" or "pizza".
class StringTerm extends Term {
//...
check(text) {
return text.startsWith(this.string)
}
}
make your terms with it.
const pastaTerm = new StringTerm("pasta")
const pizzaTerm = new StringTerm("pizza")
use it in your translate function.
function translate(text) {
return pizzaTerm.info(text)
}
back to the dream