In the code below, my return function inside the other function doesn't get run right away, but the first function is. My goal is to have the whole function running immediately.
var windowCheck = (function () {
var switcher = false;
return function () {
console.log(switcher);
if ($window.innerWidth > 480) {
if (!switcher) {
element.perfectScrollbar({
wheelSpeed: scope.wheelSpeed || 50,
wheelPropagation: $parse(attrs.wheelPropagation)() || false,
minScrollbarLength: $parse(attrs.minScrollbarLength)() || false
});
console.log('Plugin On');
switcher = true;
}
}
else {
if (switcher) {
console.log('Plugin Off');
element.perfectScrollbar('destroy');
switcher = false;
}
}
};
}());