The wording of the title probably needs re-visiting, but for now consider the following code:
var ParentControl = function()
{
this.ShowAlert = function()
{
alert('hi!');
}
this.childControl = new ChildControl();
};
var ChildControl = function()
{
// IN THIS SCOPE HERE I NEED TO CALL 'ShowAlert'
};
var parentControl = new ParentControl();
As per the comment in the code snippet above, I need instances of ChildControl
to call the 'ShowAlert' function of their parent but I don't know how.
What I've Tried
Simply calling ParentControl.ShowAlert()
where I've wrote the comment - obviously doesn't work as parentControl
is the instance (I don't want to refer to this explicitly).
I've also tried passing in the parent control to the constructor of ChildControl
but I ideally wanted to keep the child control independent from any particular type of parent.