When I first started writing my own code I never understand jQuery's 'enhanced' init constructor until later on so I stuck to a different way of constructing my objects. I was wondering if I should keep my old ways or start using my own 'enhanced' init constructor.
My Constructor:
var $ = function(selector,context,createObj) {
if(createObj) {
// actually initiating object
} else {
return new $(selector,context,true);
}
};
jQuery:
jQuery = function( selector, context ) {
// The jQuery object is actually just the init constructor 'enhanced'
return new jQuery.fn.init( selector, context, rootjQuery );
};
Actual Init:
init: function( selector, context, rootjQuery ) {
// some code
}
Changing prototype (jQuery.prototype.init.prototype=jQuery.prototype):
jQuery.fn.init.prototype = jQuery.fn;