Hey right now I’m using jQuery and I have some global variables to hold a bit of preloaded ajax stuff (preloaded to make pages come up nice and fast):
$.get('content.py?pageName=viewer', function(data) {viewer = data;}); $.get('content.py?pageName=artists', function(data) {artists = data;}); $.get('content.py?pageName=instores', function(data) {instores = data;}); $.get('content.py?pageName=specs', function(data) {specs = data;}); $.get('content.py?pageName=about', function(data) {about = data;});
As you can see, we have a huge violation of the DRY principle, but… I don’t really see a way to fix it… any ideas?
maybe an array?
You don’t need
eval()orFunction()for this. An array, as you suspected, will do the job nicely: