a、b、cの3つのオブジェクトがあります
function N(z, y){
this.z = z;
this.y = y;
}
var a = new N(true,0);
var b = new N(false, 1);
var c = new N(false, 2);
true
どのオブジェクトにその値z
とreturn
その値があるかを判別できる関数を作成したいと思いy
ます。
これは私が持っているものです:
N.prototype.check = function(){
if(this.z == true){
return this.y;
}
}
function check(){
var x;
x = a.check();
if(x !=undefined){
return x;
}
x = b.check();
if(x !=undefined){
return x;
}
x = c.check();
if(x !=undefined){
return x;
}
}
var x = check();
できます。でも、回り道をしているような気がします。これを達成するためのより良い方法はありますか?