As described by David Walsh: http://davidwalsh.name/function-attempt
function attempt(fn, args, binding) {
try {
return fn.apply(binding, args);
} catch(e) {
console.log('Exception, fix me please', e);
}
}
// Use it!
attempt(function() {
/* volatile stuff */
}, ['argOne', someVar], this);
To rotate (loop) an array with JavaScript:
var pages = ['page1', 'page2', 'page3'];
function rotate(arr) {
return arr.push(arr.shift());
}
rotate(pages); // ['page2', 'page3', 'page1']