要理解$.fn首先要理解js中prototype
函数:原型
定义:每一个构造函数都有一个属性叫做原型prototype。
作用:为一个特定类声明通用的变量或者函数。
不需要显式地声明一个prototype属性,因为在每一个构造函数中都有它的存在。
function Person(name, height){
this.name =name;
this.height = height;
}
Person.prototype.country = 'China';
Person.prototype.say = function(){
alert(this.name +' is from ' + this.country +'and height is ' + this.height);
}
var p1 = new Person('tom','160');
var p2 = new Person('jack', '80');
p1.name >>tom
p1.height >>160
p1.country >>china
p1.say() >>tom is from china and height is 160
p2.name >>jack
p2.height >>80
p2.country >>china
p2.say() >>jack is from china and height is 80
country和say方法是person的通用属性和方法, 存在于于构造函数,所以每次建立以新的对象都会初始化prototype的属性和方法
—2015/12/14