JS: Throttle and Debounce

by kyllle

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>

SCSS

* {
  -webkit-font-smoothing: antialiased;
}

body {
    padding: 5%;
}

JavaScript

console.clear();

// https://css-tricks.com/debouncing-throttling-explained-examples/

$(window).on('resize', _.debounce(function() {
	console.log('Debounce');
}, 400));

$(window).on('resize', _.throttle(function() {
	console.log('Throttle')
}, 400));