I'm starting Addy Osmani's amazing book on javascript design patterns but can't seem to get off the ground. Can anyone tell me what's wrong here with my approach (I'm using Raphael, just for fun.):
var myPaper = Raphael('container', '800', '600');
var myScene = function() {
var c1 = myPaper.circle(50, 50, 40);
var c2 = myPaper.circle(50, 150, 40);
var c3 = myPaper.circle(50, 250, 40);
c2.attr("fill", "red"); // yep!
return {
firstCircle: c1
};
}
// at some point later i want to call the function...
myScene();
// ...then even later I want to refer to one of the circles
// but without creating another global variable.
myScene.firstCircle.attr("fill", "red"); // nope!
console.log(myScene.firstCircle); // undefined!