how do I get this reference right, it returns “foo undefined”;
function myObject(){
this.foo="bar"
this.foo2=this.myMethod.foo3;
alert(this.foo2);
}
myObject.prototype.myMethod= {
foo3:'foo'+this.foo;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you do this…
the value of
thisis being evaluated from the current context where the object is being created, which likely doesn’t have afooproperty.Not sure why you’re calling it
myMethod, but assigning an Object, but if you actually made it a method, you could then get the correctfoovalue.