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?
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.
精彩评论