Start with the main function:
var $ = function(expr) { return $.select(expr); }
Then add additional functionality:
$.select = function(expr) { console.log("selecting " + expr); return $;
You can see how this template is used in jQuery by looking at the source :
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 ) { var match, elem, ret, doc; // Handle $(""), $(null), or $(undefined) if ( !selector ) { return this; } // contents of init() here } }
source share