【发布时间】:2012-12-13 22:00:56
【问题描述】:
我有这个东西
function paymentPlan(name, price, days, active){
this.name=name;
this.price=price;
this.days=days;
this.active=active;
}
var plan_1 = new paymentPlan("unlimited", 0, -1, -1);
var plan_2 = new paymentPlan("starter", 100, 7, 2);
我需要通过从另一个变量构建变量实例来选择其中一个对象实例,本质上是将数字添加到引用的末尾
例如,如果我需要在选择时打印出 plan_2 的名称,我需要像这样构建参考
var plan_id = 2;
alert( plan_+plan_id.name );
我该怎么做?
【问题讨论】:
-
? plan_id 和 plan_ 不在上面的对象/代码中,你能澄清一下你的意思吗?
-
为什么不用数组来代替,索引就是计划id
标签: javascript variables object reference