So using the following part of my code, I've been trying to find the object's name ("object's name" refers to foo, bar, baz, and jar below. Sorry if that's the improper term, couldn't find any examples like this one on the web that termed them) using the values of the constructed function. To give an example:
function myFunction(){
foo = new component(50, 50, "first", "red");
bar = new component(50, 100, "sec", "red");
baz = new component(0, 50, "third", "blue");
jar = new component(0, 100, "fourth", "blue");
}
function component(x, y, id, color){
this.x = x;
this.y = y;
this.id = id;
this.color = color;
}
So if I have the value of both x and y, 50 and 100 respectively, what method would I use to make it so that the program will recognize that the constructor with these values is bar? If doing this using two values is impossible, using only one value is totally fine since I can always just combine the two into one. So far the best thing I've been able to come up with that somehwhat worked was that "foo instanceof component" is true, so maybe there's some method that I've yet to find that's basically the opposite of instance of? Thank you in advance.
foo
,bar
,baz
, andjar
aren't constructors, they are objects.component
is the only constructor here. I think I understand though. So you want to getx
andy
as input, and return the object that it's associated with? – 4castle 1 hour ago