//var jQuery = (function(){

var jQuery = function(selector){

return new jQuery.fn.init();
} jQuery.prototype = {
constructor: jQuery,
init:function(selector){
if( selector == window ){
return this;
}
}
} jQuery.fn = jQuery.prototype;

//})();
        $ = jQuery;
var $window = $(window);

alert($window);
1.为什么注释的语句去掉之后对象无法创建2.new jQuery.prototype.init();
按照我的理解,jQuery.fn指向的jquery的原型对象,该原型对象调用自身的init()方法,返回了一个this对象,
那么岂不是new this;为什么还能使用new运算符3.为什么去掉了new运算符之后,jQuery.prototype.init() 结果变成了undefined4.selector参数为什么能够被带到init方法中。并没有函数进行显式的参数传递啊。

解决方案 »

  1.   

    1,2,3 不回答
    都是语法基础的东西4的话
    var jQuery = function( selector, context ) {
    // The jQuery object is actually just the init constructor 'enhanced'
    return new jQuery.fn.init( selector, context );
    },不知道你的代码哪里复制的 一般jquery的代码都是上面这样的调用方式 
      

  2.   

    回楼上,
    代码自己写的,从jquery里面看到的复制出来,缩减了一些东西,
    为什么我没有用init传递 
    if( selector == window ){
                        return this;
                    }
    依然执行了呢
      

  3.   

    因为
    你function定义的时候定义了形参
    如果调用的时候 没有对这个形参传参数 则 这个参数默认就是 undefined