dependency in javascript object
javascript
Solution
`this`, in your definition does not refer to r, but to the actual context (probably `window`)
you should define it like this:
var r = {
a1: function() {}
/* a3: r, // Here r is not yet assigned. First the object is created, then its value
// is assigned to r.
*/
};
r.a2 = r.a1;
r.a3 = r.a1;
Problem
I have this JavaScript code: ``` var r = { a1:function() { alert('hey!'); }, a2:this.a1 /*, a3:r.a1, //<--Make an error when running a4:a1 //<--Make an error when running */ }; ``` When executing `r.a1()` I get an alert but when executing `r.a2()` I get message: ``` TypeError: r.a2 is not a function ``` Why is it? How can I make this work in in one statement?