Wrap a script for use in multiple scenes or views

/*I wish someone had posted this for me 5 years ago. If you are new to js then you may find yourself copying the same code multiple times to execute on multiple scenes or views. Drop your code where it says 'script here' to run on multiple scenes or views. */

//for views

var wrap_view = ["168", "178"]; //Change to your views
wrap_view.forEach(functionName);
function functionName(selector_view){

$(document).on("knack-view-render.view_" + selector_view, function(event, view, data) {
//Script here
});
}

//and for scenes

var wrap_scene = ["168", "178"]; //change to your scenes

wrap_scene.forEach(functionName);
function functionName(selector_scene){

$(document).on("knack-scene-render.scene_" + selector_scene, function(event, scene, data) {
//Script here
});
}

Thanks, Brad. This one is super useful but I'd hardly call you a newbie. ;)

Awesome Justin, never occurred to me that was possible.  But then I'm a JS newbie too!

Don’t forget that last bracket!