I come from a Java background and want to refer to things in a similar way. I’m not sure where to look. pseudo code:
var elements = [];
class Element
{
constructor()
{
this.isClicked;
}
mouseOver()
{
///returns true if mouse is over
}
click()
{
this.isClicked = true;
}
unclick()
{
this.isClicked = false;
}
}
class Parent extends Element
{
constructor()
{
this.children = [];
this.x = 0;
this.y = 0;
elements.push(this)
}
addChild()
{
children.push(new Child(this));
}
}
class Child extends Element
{
constructor(Parent p)
{
this.parent = p;
this.x = 0;
this.y = 0;
elements.push(this)
}
move()
{
this.x = parent.x;
this.y = parent.y;
}
}
var liveElement;
function mousePressed()
{
for(Element e : elements)
{
if(e.mouseOver)
{
liveElement = e;
liveElement.click();
}
}
}
function mouseReleased()
{
liveElement.unclick();
liveElement = null;
}
Is it possible to do this kind of thing in vanilla JavaScript? I would also like to refer to all the objects horizontally in elements. The Child objects should be able to refer up to parent when needed.
Elementsclass and do away withParentandChild?