Downshifting Code

This is highly applicable to javascript onresize() event where it gets fired every time the user moves the cursor to resize

by KevinIsNowOnline

JavaScript

var ns = {
    timeOutId: 0,
    _process: function () {
        console.log('hello');
    },
    process: function () {
        clearTimeout(this._timeoutId);
        var me = this;
        this._timeoutId = setTimeout(function () {
            me._process();
        }, 2000);
    }
};

window.onresize = function (event) {
    ns.process();
}