基于对象是指javascript操作的是一个个对象的属性或方法,通过一定函数组合来完成功能。面向对象是指一种程序设计概念,主要特点有类封装,继承,重载等。跟基于对象概念不一样。javascript也可以用面向对象的概念来编程。

解决方案 »

  1.   

    function Test()
    {}
    var first=new Test();
    不是创建对象了吗???
      

  2.   

    function Test()
    {}
    var first=new Test();
    --------
    这个first是个对象实例吗?
    如果是,它有什么属性?
    如果不是,那么new Test算一个什么?我觉得,从语法上来说,真的好难理解这个概念,恳请高手指教非常感谢。
      

  3.   

    <html>
    <head>
    <script language="javascript">
    function system(a){
    this.login=function(){
    return(6);
    }
    }
    nnn= function(){}
    nnn.prototype=new system();var ttt=new nnn();
    a=ttt.login();
    alert(a);</script></head><body onload="init()"></body></html>
      

  4.   

    function Test(n){
      this.publicValue=0;
      var privateValue=0;  this.publicMethod=function(n){
        this.publicValue=n;
        privateMethod(n*3);
      }  var privateMethod=function(n){
        privateValue=n;
      }  this.main=function(n){
        this.publicMethod(n);
        privateMethod(n*0.2);
        alert(this.publicValue);
        alert(privateValue);
      }  this.main(n);
    }var test=new Test(43);
    //创建实例test.publicMethod(789);
    alert(test.publicValue);//以下两行会出错,因为privateMethod和privateValue都是私有的,不能调用,但在类中可以调用。
    test.privateMethod(32);
    alert(test.privateValue);//test.main();
    main()方法是在创建实例时就会运行的,是在构造方法里调用的,这个例子应该可以说明一些东西,JS里有一句话很重要,[方法即对象],你自己好好想想。因为方法的定义里的全局变量和局部变量有异曲同工之处。
      

  5.   

    Test.prototype=OtherObject;
    这样的话,Test就会继承OtherObject另外,给Test再增加一个成员方法用以下方法
    Test.prototype.foo=function(){
      //......
    }