JQ源码分析(2.0.3)---定义变量个函数

1、(function(window,undefined){

}())//匿名函数自执行,防止与外面变量冲突,传入window可以减少查找损耗

2、_$ = window.$,//用于防止外界改变$符号的指向

3、jQuery = function( selector, context ) {

return new jQuery.fn.init( selector, context, rootjQuery );
},

function a(){
return new a.prototype.init()
}
a.prototype.init=function(){

}
a.prototype.css=function(){
console.log(31)

}

a.prototype.init.prototype = a.prototype;
a().css()//通过这样的方式来改变写法

4、第100行

constructor: jQuery,//用来使得constructor的指向矫正为jQuery,以防被外界改变

var a = function(){}

a.prototype.name = "kone"

a.prototype.sex = "man"

a.prototype = {

construtor:a

name:"kone"

sex:"man"

}

由于a.prototype.construtor = a();而construtor容易被外界改变指向,所以需要重新矫正construtor的指向。

 

posted @ 2017-12-12 20:47  码我滴码  阅读(112)  评论(0编辑  收藏  举报