【发布时间】:2011-06-21 01:38:38
【问题描述】:
我有这个 Car 功能:
var Car = function(vendor, model, year) {
return {
vendor: vendor,
model: model,
year: year,
name: (function() {
return vendor + " " + model + " " + year;
})()
};
};
var foo = Car("Toyota","Corola",2007);
alert(foo.name); //alerts "Toyota Corola 2007"
这可行,但我希望name 能够根据vendor、model 和year 进行更改。
taxi.vendor = "Mitsubishi";
alert(taxi.vendor); //still alerts "Toyota Corola 2007"
如何根据vendor属性的变化,让它提醒Mitsubishi Corola 2007?
编辑:还有问题 -- name 必须保留一个不需要作为函数调用的属性。
【问题讨论】:
-
我有麻烦了,我没有查看之前的帖子! [前期酷讨论][1][1]:stackoverflow.com/questions/6349121/…
标签: javascript json