我有一个对象:
location = {place1: distance1, place2:distance2};
如何设置诸如 location.name = location 之类的内容,以便以后可以访问“位置”字符串?
像这样的东西会起作用吗?
location = {
place1: distance1,
place2: distance2
location.name = "location";
}
提前致谢!
我有一个对象:
location = {place1: distance1, place2:distance2};
如何设置诸如 location.name = location 之类的内容,以便以后可以访问“位置”字符串?
像这样的东西会起作用吗?
location = {
place1: distance1,
place2: distance2
location.name = "location";
}
提前致谢!
location = {
place1: distance1,
place2: distance2,
name : "location"
}
在 js 中几乎一切皆有可能:)
my_location = {
place1: distance1,
place2: distance2
};
my_location.name = "location";
alert(my_location.place1 + ' ' + my_location.place2 + ' ' + my_location.name);
另一种方式:
function MyLocation(distance1, distance2){
this.place1 = distance1;
this.place2 = distance2;
}
my_location = new MyLocation(dist1, dist2);
my_location.name = "location";
alert(my_location.place1 + ' ' + my_location.place2 + ' ' + my_location.name);