Besides the fact that success is spelled wrong, there is no way to be certain yet.
The tricky thing about JavaScript's use of "this" is that "this" is not determined by the method's definition but by how it is invoked.
I explained this recently in another similar question:
How the "this" affected in a method's method?
For example, I can define a variable that points to your function:
var blah = this.onSucess;
blah(); // "this" will be undefined
var bleh = {
test: this.onSuccess
}
bleh.test(); // "this" will be the object literal.
When getCurrentPosition calls your callback function, it probably just calls it directly:
onSuccess(position);
therefore "this" is not defined.
What you can do is pass it a wrapper/proxy function that has a closure reference back to your Geolocation object so it can call this.onSuccess:
function Geolocation(){
this.maximumAge = 3000;
this.timeout = 20;
this.enableHighAccuracy = true
this.geolocation = navigator.geolocation.getCurrentPosition(function (position) {
this.onSucess(position);
},
function (error) {
this.onError(error);
},
{
maximumAge : this.maximumAge,
timeout : this.timeout,
enableHighAccuracy: this.enableHighAccuracy
});
}
A short-hand way to do this, as shown by David, is to use Function.bind, which returns a wrapper function doing just what I described, like so:
function Geolocation(){
this.maximumAge = 3000;
this.timeout = 20;
this.enableHighAccuracy = true
this.geolocation = navigator.geolocation.getCurrentPosition(this.onSucess.bind(this),
this.onError.bind(this),
{
maximumAge : this.maximumAge,
timeout : this.timeout,
enableHighAccuracy: this.enableHighAccuracy
});
}