Skip to content

Instantly share code, notes, and snippets.

Last active Aug 29, 2015
What would you like to do?
jQuery Reimagined
/* Redefine jQuery methods as "raw" methods */
(function($) { "use strict";
function wrap(method) {
return function() {
var jq = $(this),
result = jq[method].apply(jq, arguments);
if (result && result.constructor === $)
result = result.toArray();
return result;
function wrapAll(out) {
var x = $();
for (var name in x)
if (typeof x[name] === "function")
out[name] = wrap(name);
return out;
wrapAll(window.jake = {});
// Create bindings for just the methods that we need
let { find, html } = jake;
// Find all the divs with class="myClass", then get all of the "p"s and replace their content.
// Notice that we didn't have to worry about wrapping/unwrapping elements and NodeLists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment