Skip to content

Instantly share code, notes, and snippets.

@kswlee
Created June 27, 2012 14:57
Show Gist options
  • Select an option

  • Save kswlee/3004628 to your computer and use it in GitHub Desktop.

Select an option

Save kswlee/3004628 to your computer and use it in GitHub Desktop.
Simplified jQuery 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 );
},
// A central reference to the root jQuery(document)
rootjQuery;
jQuery.fn = jQuery.prototype = {
constructor: jQuery,
init: function( selector, context, rootjQuery ) {
this.context = this[0] = document.body;
this.length = 1;
return this;
},
// The default length of a jQuery object is 0, and make it act like []
length: 0,
splice: [].splice
};
// Give the init function the jQuery prototype for later instantiation
jQuery.fn.init.prototype = jQuery.fn;
rootjQuery = jQuery(document);
return jQuery;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment