87,922
社区成员
发帖
与我相关
我的任务
分享
ListCommon2.First=function(first)
{
alert("111first do"+first);
}
ListCommon2.prototype.First=function(first)
{
alert("111first do"+first);
}
var a = function() {}
a.b=function() {
alert(1);
}
a.b(); //1
A = new a;
A.b() //报错,因为a的实例中没有方法b
var a = function() {}
a.b=function() {
alert(1);
}
a.prototype.c=function(){
alert(2);
}
a.b(); //1
A = new a;
A.b() //报错,因为a的实例中没有方法b
A.c() //2
简单说就是属性挂到对象原形上可以继承!function A(){
this.first=function(){
alert('first');
}
}
可以通过:
var a=new A()
a.test();//来调用test方法
接下来,lz的问题:
A.foo=function(){
alert('foo');
}
a.foo();//报错:木有定义
但是A.foo();没问题。这里对A增加了一个静态方法。
如果是对prototype进行调教:
A.prototype.ppp=function(){
alert('ppp');
};
A.ppp();//出错
a.ppp();//正常
到这里有没有了解一些这两个的区别?