2013年11月14日星期四

JQuery is a "Class" or object problem


Today saw the jQuery source code under which part of the code is so
(function (window, undefined) {
var document = window.document,
navigator = window.navigator,
location = window.location;
var jQuery = (function () {

var jQuery = function (selector, context) {
return new jQuery.fn.init (selector, context, rootjQuery);
},
.........
}) ();

.........
}) (window);

ellipsis is omitted code.
I doubt : var jQuery = function (selector, context) {
return new jQuery.fn.init (selector, context, rootjQuery);
}, this definition has been defined as a class of jQuery ( can not think so ) , while in the outer nested jQuery jQuery is an anonymous function execution results that object.

jQuery in the end it is a class or an object ? Which god knows next to explain to the younger , be grateful !
------ Solution ---------------------------------------- ----
I can say it , not to say that the object-oriented inside everything is an object of it , I understand that , jquery can say that he is a class can also be said that he is an object, but he was a doors separate voice , do not know js inside or what is called the class , the class is also an object
------ Solution ---------------------- ----------------------
can be understood as class
------ Solution ----------- ---------------------------------
js is weakly typed . jQuery is js libraries.
Java classes in C + + template is similar to that for the class loader which is actually an object.
So the boundaries of classes and objects is not so entirely different , you do not need to tangle here.
------ Solution ---------------------------------------- ----
according to what you say , can be understood as the class .
------ For reference only -------------------------------------- -
javascript no java sense of class , only the prototype,
javascript no java sense objects , only the Map.

没有评论:

发表评论