Currently diving into Addy Osmani's fantastic read on javascript design patterns, however, I'm facing a roadblock. Can someone help me identify the issue with my approach? (I'm experimenting with Raphael 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"); // Yes!
return {
firstCircle: c1
};
}
// Later on, I want to execute the function...
myScene();
// ...and even later, I wish to reference one of the circles
// without having to create another global variable.
myScene.firstCircle.attr("fill", "red"); // Incorrect!
console.log(myScene.firstCircle); // undefined!