Defining and calling function in one step
You can try: (window.powers = function(i) { /*Code here*/ alert(‘test : ‘ + i); })(2); <a href=”#” onclick=”powers(654)”>Click</a> Working link : http://jsfiddle.net/SqBp8/ It gets called on load, and I have added it to an anchor tag to change the parameter and alert.