Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created January 14, 2011 01:39
Show Gist options
  • Save xeoncross/778996 to your computer and use it in GitHub Desktop.
Save xeoncross/778996 to your computer and use it in GitHub Desktop.
A jQuery-like global JavaScript selector core
var jQuery = (function() {
// Define a local copy of jQuery
var jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context );
};
jQuery.fn = jQuery.prototype = {
init: function( selector, context ) {
this.selector=selector.style?selector:document.getElementById(selector);
return this;
},
// Start with an empty selector
selector: ""
}
// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;
// Expose jQuery to the global object
return (window.jQuery = window.$ = jQuery);
})();
console.log(jQuery);
console.log($);
console.log($('text'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment