两个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中,但还是同样的错误。
特上来发帖求救,在线等待答案。
谢谢各位。
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中,但还是同样的错误。
特上来发帖求救,在线等待答案。
谢谢各位。
this.startCar() {
var c = new car("大众", "黑色");
c.start();
}
}
这样试试
var car = function(brand, color) {
this.start = function() {
}
}var people = function() {
this.startCar = function() {
var car = new car("大众", "黑色");
car.start();
}
}
}car.prototype =
{
start:function(){}
}
var people = function() {
this.startCar = function() {
var car = new car("大众", "黑色");
car.start();
}
}
this.start() {
};
};
this.start=function(){
}
};
var people = function() {
this.startCar=function(){
var car = new car("大众", "黑色");
car.start();
}
}
var a=new car();
function car(brand, color){
this.start=function() {
};
};