JQuery

How JQuery Works

var jQuery = (function () {
  // Define a local copy of “k”
  // The first parameter is selector and the second parameter is context.     
  var k = function (selector, context)
  {
    // The k object is actually just the init constructor 'enhanced'
    // A new instance of init function class is created and returned. 
    // The init function class defined later on k's prototype method. 
    // It is a JavaScript style's class
    var kobj = new k.fn.init(selector, context);
    return kobj;
   };

  //Define k’s fn prototype, specially contains init method
  // init method is available by all instance of k function     
  k.fn = k.prototype = {
        init: function (selector, context)
        {
            if (!selector)
            {
                return this;
            }
        }
    };

 // Give the init function the “k” prototype for later instantiation
 // k's prototype has init member method, in the meanwhile, init function's prototype is 
 // with k function's prototype. This is a circular reference
 // it is the way jQuery make the return of init function can have access to all the methods
 // defined on K. 

  k.fn.init.prototype = k.fn;
  // Return “k” to the global object

  return k;
})();

results matching ""

    No results matching ""