Skip to content

Instantly share code, notes, and snippets.

@derick-montague
Last active April 20, 2017 02:21
Show Gist options
  • Save derick-montague/05cecc75ee0855985fd2 to your computer and use it in GitHub Desktop.
Save derick-montague/05cecc75ee0855985fd2 to your computer and use it in GitHub Desktop.
Various vanilla js replacements for jQuery methods
module.exports = {
extend: function extend() {
for (var i = 1; i < arguments.length; i++)
for(var key in arguments[i])
if(arguments[i].hasOwnProperty(key))
arguments[0][key] = arguments[i][key];
return arguments[0];
},
domReady: function domReady(fn) {
if (document.readyState !== 'loading') {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
},
debounce: function debounce(func, wait, immediate) {
var timeout;
return function () {
var context = this, args = arguments;
var later = function () {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment