Deferred javascript execution on window resize

A simple example how to run deferred jаvascript on window resize

var doit;
window.onresize = function() {
    clearTimeout(doit);
    doit = setTimeout(function() {
       // Your script
    }, 500)
}