1. function debounce(fn, delay) {
    2. var timer = null;
    3. return function () {
    4. var context = this;
    5. if(timer) {
    6. clearTimeout(timer);
    7. }
    8. timer = setTimeout(() => {
    9. fn.call(context, ...arguments);
    10. }, delay || 500);
    11. }
    12. }
    13. window.onresize = debounce(function() {
    14. console.log('window onresize end');
    15. }, 500)