Skip to content

Instantly share code, notes, and snippets.

@ericelliott
Last active November 18, 2017 00:07
Show Gist options
  • Save ericelliott/bde5fcaf74abf26b9039 to your computer and use it in GitHub Desktop.
Save ericelliott/bde5fcaf74abf26b9039 to your computer and use it in GitHub Desktop.
classy jQuery - an alternate reality where jQuery really sucked and never took off
/**
classy jQuery - an alternate reality where jQuery really sucked and never took off
OR
Why nobody would have liked jQuery if it had exported a class instead of a factory.
**/
// This just looks stupid. Are we creating a new DOM element
// with id="foo"? Nope. We're selecting an existing DOM element
// with id="foo", and wrapping it in a jQuery object instance.
var $foo = new $('#foo');
// Besides, it's a lot of extra typing with literally ZERO gain.
var $bar = new $('.bar');
var $baz = new $('.baz');
// And this is just... well. I don't know what.
var $bif = new $('.foo').on('click', function () {
var $this = new $(this);
$this.html('clicked!');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment