The code below passes a string to validate and function to be called if validation succeeds. In the end we reach to callback, which is object function but if fails to recognize itself as such. How to overcome the situation?
function A(arg) {
this.b = arg
this.validate = function(name, cb) {
textarea1.textContent += ("in validate, b = " + this.b + ", f = " + this.f) + "\n"
return cb(name)
}
this.f = function(name) {
textarea1.textContent += ("in f, b = " + this.b) + '\n'
}
}
var a = new A(1)
a.validate("name", a.f)
<textarea id="textarea1" cols=100 rows=5></textarea>