Solving this issue with arrow function
var Word = function(t){
var text = t;
var translate = function(lang){
switch(lang){
case "pig latin":
t = function(){return this.text.substring(1, this.text.length) + this.text.substring(0,1) + "a"}
break;
default:
t = function(){return "I dont speak" + lang}
}
return t()
}
return {"text": text, "translate":translate}
}
var Word = function(t){
var text = t;
var translate = function(lang){
switch(lang){
case "pig latin":
t = ()=>{return this.text.substring(1, this.text.length) + this.text.substring(0,1) + "a"}
break;
default:
t = ()=>{return "I dont speak" + lang}
}
return t()
}
return {"text": text, "translate":translate}
}