Created
January 14, 2011 01:39
-
-
Save xeoncross/778996 to your computer and use it in GitHub Desktop.
A jQuery-like global JavaScript selector core
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
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