Torben
Torben

Reputation: 1290

Access parent object from function in JavaScript

Short question. I have the following situation:

function callbackTest(data, callback) {
     callback.call(data);
}

var map = new Map("Worldmap");
var data = "My data";
callbackTest(data, map.processData);

So, my question is, wheather or not it is possible to access the map object from inside the callbackTest function?

Upvotes: 2

Views: 716

Answers (1)

Nick Craver
Nick Craver

Reputation: 630379

You can't access map unless you pass it in, or processData has a reference back to map. Basically there's no inherent .parentObject property present when dealing with a generic object here.

Upvotes: 2

Related Questions