I have a code and it does as follows
var Device = function(temp){
this.list = temp;
Device.prototype.getList = function(){
return list;
};
Device.prototype.foo = function(tempFunc){
navigator.geolocation.watchPosition(
function(pos) {
//I want to call getList here so lets do it
//Method No1
var list = this.getList();
//Method No2
var list = Device.prototype.getList();
//Method No3
var list = getList.call(Device)
},
funciton(){
console.log("Error")
}
};
};
In all three methods I am getting an error. 1.object [object global] has no method called get list. 2. list is undefined 3. Can not call a undefined.
I also tried to call the foo method in this context then pos is not recognized in the context and passing the getList as a argument did not help me either. I think I do have understanding of the issue here but I do not know how to handle it. I need the getList method to be called in the anonymous function but that function gets called in the global context is my thinking. Could anyone sort this out for me.