Last active
December 22, 2015 17:59
-
-
Save nathggns/6510223 to your computer and use it in GitHub Desktop.
Something I wish was in ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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