Skip to content

Instantly share code, notes, and snippets.

@nathggns
Last active December 22, 2015 17:59
Show Gist options
  • Save nathggns/6510223 to your computer and use it in GitHub Desktop.
Save nathggns/6510223 to your computer and use it in GitHub Desktop.
Something I wish was in ES6
jQuery.prototype.fromObject = function(object) {
if (object instanceof jQuery) {
return object;
}
return $(object);
}
function handlejQueryObject(jQuery object) {
// object will always be a jquery rep of the body element
};
handlejQueryObject('body');
handlejQueryObject(document.body);
handlejQueryObject($('body'));
handlejQueryObject($(document.body));
// This is how you'd do it in ES5.
function handlejQueryObject(object) {
if (!(object instanceof jQuery)) {
object = $(object);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment