Your problem is that the this.onLanguageChange
doesn't refer to the right handler because this
within the language
function is unbound and so when it's executed points to the global object (i.e., window
). You can do a few things to fix it:
- Add
var self = this;
before defininglanguage
and refer toself.onLanguageChange
. - Add
.bind(this)
after the function that you're assigning torender
. - Call
.map(language, this)
to tellmap
what context to use when callinglanguage
. This is the simplest and cleanest solution.
If you're not familiar with JavaScript's scoping rules and how this
works, I suggest reading up on it.