0

I created this jsfiddle for my question: https://jsfiddle.net/5eq19xm4/1/

function Parent()
{
  this.ParentCallback = function(){
        debugger;
    //check value of this
  }
}

function Child(parentCallback)
{
this.ChildCallback = parentCallback;
}

I don't understand why the value of "this" in the function "ParentCallback" is the child instead of the parent and how to workaround without a reference from the child to the parent.

I know this is something about the context of call but it's not clear in my mind.

I don't understand how I could refer to the parent in the function.

Neb
  • 354
  • 2
  • 12
  • because you call the parentCallback from the child-context. The parentCallback inherits the context from the calling function. If you need to access the parent scope do it like so: https://jsfiddle.net/19aefkca/ – newBee May 11 '16 at 13:32
  • I used $.proxy to solve my problem. Thanks anyway – Neb May 11 '16 at 14:26

0 Answers0