var fn = function() {
this.method1 = function() {
return this.public;
};
this.method2 = function() {
return {
init: function() { return this.public; }
}
};
fn.prototype.public = "method prototype";
};
create object fn
var object = new fn();
object.method1() // "method prototype"
object.method2().init(); // undefined
this.public Prototype in method2().init() function run return undefined ?
Is there an alternative to Prototype?
thank you.
The issue is related to the different scope in which
thisis bound oninitfunction ofmethod2(), so try this:so