学习 Javascript 并遇到一个我似乎无法解决的问题。我创建了一个对象和几个实例,并对它们做了一些 document.write。问题是,他们不会工作。进一步的问题是,它会阻止所有Javascript 工作。当我在一开始就放入一个 window.alert 以确保我将它链接到我的 HTML 时,这也不起作用(但是当对象被注释掉时 window.alert 确实有效)。有人愿意解释我在这里做错了什么吗?
window.alert("TEST!!!");
function car(seats, engine, theradio) {
this.seats = seats;
this.engine = engine;
this.theradio = theradio;
}
var work_car = new car("cloth", "V-6", "tape deck");
var fun_car = new car("leather", "V-8", "CD Player");
var engine_type = work_car.engine;
var seat_type = fun_car.seats;
var radio_type = fun_car.theradio;
document.write("I want a car with " + seat_type + " seats." <br />);
document.write("Oh, and it should have " + engine_type + " and a " + radio_type ".");