本帖最后由 xuexiaodong2009 于 2014-06-09 14:05:01 编辑

解决方案 »

  1.   

    我来说一个区别
    如有以下function:
    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();//正常
    到这里有没有了解一些这两个的区别?
      

  2.   

    ListCommon2.First这个相当于OO语言的静态方法ListCommon2.prototype.First这个则是类的方法ListCommon2.prototype.First需要new一个实例出来才能调用First,ListCommon2.First则可以直接调用
      

  3.   

    ListCommon2.First                           静态方法,调用方式:ListCommon2.First()ListCommon2.prototype.First         实例方法,调用方式:new ListCommon2().First()
      

  4.   

    ListCommon2.First 则 First 只对当前的 ListCommon2 有效
    ListCommon2.prototype.First 是对原型的设置,Firs 对所有基于 ListCommon2 的对象有效
      

  5.   

    prototype称为原型对象,它返回对象类型原型的引用
    能够让你定义的类可以被继承,可被扩展
    参考:
    http://www.cnblogs.com/yjf512/archive/2011/06/03/2071914.html
      

  6.   

    如果你能从动态语言的角度来考虑这个问题,也许会更容易理解一点,例如php,asp.net,javajs中既然没有类的概念,又是怎样来模拟类,以及面向对象的特性之一:继承
      

  7.   


    var a = function() {}
    a.b=function() {
        alert(1);
    }
    a.b(); //1
    A = new a;
    A.b() //报错,因为a的实例中没有方法bvar 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简单说就是属性挂到对象原形上可以继承!
      

  8.   

    从面相对象来说第一种方法是一个类的静态方法,可以直接通过类名.方法名访问
    第二种是类里面定义的方法,非静态的,需要通过实例化成对象才能访问
    class ListCommon2{
    public static void ff(){};
    }
    ListCommon2.ff();class ListCommon2{
    public void ff(){};
    }
    new ListCommon2().ff();
      

  9.   

    难道你们基本都是这样定义函数的?  为毛我直接是用 function a (){}   或者  var a = function(){}