两个js文件:
car.js
var car = function(brand, color) {
    this.start() {
    }
}people.js
var people = function() {
    this.startCar() {
        var car = new car("大众", "黑色");
        car.start();
    }
}
我把这两个js按照先后顺序在页面head中引用,但是在new car的时候,报错说car undefined。
然后我又在people的开头写入:document.write("<script type='text/javascript' src='car.js'></script>"),并且在页面中指引用people.js,但还是一样的错误。
再后来,我干脆把car.js里的代码复制到people中,但还是同样的错误。
特上来发帖求救,在线等待答案。
谢谢各位。

解决方案 »

  1.   

    var people = function() {
        this.startCar() {
            var c = new car("大众", "黑色");
            c.start();
        }
    }
    这样试试
      

  2.   


    var car = function(brand, color) {
        this.start = function() {
        }
    }var people = function() {
        this.startCar = function() {
            var car = new car("大众", "黑色");
            car.start();
        }
    }
      

  3.   

    var car = function(brand, color) {
    }car.prototype = 
    {
        start:function(){}
    }
    var people = function() {
        this.startCar = function() {
            var car = new car("大众", "黑色");
            car.start();
        }
    }
      

  4.   

    function car(brand, color){
    this.start() {
        };
    };
      

  5.   

    你对对象的属性怎么构造还没有弄清楚var car = function(brand, color) {
    this.start=function(){
    }
    };
    var people = function() {
    this.startCar=function(){
    var car = new car("大众", "黑色");
    car.start();
    }
    }
    var a=new car();
      

  6.   

    不好意思,错了!应该是:
    function car(brand, color){
    this.start=function() {
       };
    };