I have this example code:
var foo = {
self: this,
init: function(){
self.doStuff();
},
doStuff: function(){
alert('doing stuff');
}
}
foo.init();
Why the refence “self” doesn’t work?
Thanks!
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.
Following up on Qeuntin’s response you would use the following to achieve what you’re looking for
EDIT: Since it’s been pointed out that whilst this solves OP’s problem (i.e it works) it isn’t exactly how you should go about it. So, here’s a scoping reference.