500full

The Great VAR Escape

“Why didn’t anyone think of that before? It’s so stupid, it’s positively brilliant!”

Has anyone else had a problem of wanting to use a VAR outside of the function they are associated  with?  Yeah didn’t think so!

I had to do such a thing my last job, i had to wait for the dom to load the get .height() value and then use it later if needed via jQuery address!

So here is what i came up with, a little bit of code that could help you if you do need to do such a stupid thing as well!

The code:


<script type="text/javascript">
backdoor(info, news, forms, reports, articles, otherschol);
// Pass the functions out via a functions parameters

}); // End of function that holds the vars

var newVars = []; // declare and empty array

function backdoor(one, two, three, four, five, six){

	newVars = [one, two, three, four, five, six];
	// Push the vars out of the parameters into the array to be used again!

}
</script>

Add your comment

Latest tweets
  • Sorry, twitter is down