I've got a calculation script that executes when the page loads, but also when the window gets resized. The code in between is exactly the same; not re-used.
So I was wondering, not if, but how do I re-use Javascript code?
I've tried a few stuff, like the next piece, but that ain't working.
$(function reUse() {
alert('Either the page got resized or the page loaded!');
console.log('Either the page got resized or the page loaded!');
});
$(window).resize(function() {
reUse();
});
So what should be the correct way of formatting?