0

所以我有一个主干视图,我有这个方法

inscription: function() {
    var self = this;
    navigator.geolocation.getCurrentPosition(function(position) {
    //I need to use self here because the context of this function
    //is not my Backbone View

如何在 getCurrentPosition 回调中使用它?

4

1 回答 1

0

使用_.bind -_.bind(fn, context)在你的情况下:

var self = this;
//...
var somefn = _.bind(function(position) {
   var self = this;
   //this/self refer to outer this
}, self)
navigator.geolocation.getCurrentPosition(somefn)
于 2013-10-30T01:43:07.467 回答