LUCKILY, we work in JAVASCRIPT, the best PROGRAMMING language in the world. that means we can use classes to make our terms.
this language translates "pasta" (yet again), using a class.
TRANSLATED:
first make a base term class.
class Term {
check(text) {
// return true or false
}
bite(text) {
// return a string or null
}
tail(text) {
// return a string or null
}
travel(text) {
// return a string
}
error(text) {
// return a string or null
}
}
then extend the class to make pasta!
class PastaTerm extends Term {
check(text) {
//...
}
bite(text) {
//...
}
tail(text) {
//...
}
travel(text) {
//...
}
error(text) {
//...
}
}
construct the term.
const pastaTerm = new PastaTerm()
then use it.
function translate(text) {
return {
check: pastaTerm.check(text),
travel: pastaTerm.travel(text),
bite: pastaTerm.bite(text),
tail: pastaTerm.tail(text),
error: pastaTerm.error(text),
}
}
back to the dream