捕获google.maps.Marker.prototype.setPosition调用
(function(){
var setPos = google.maps.Marker.prototype.setPosition;
google.maps.Marker.prototype.setPosition = function(latLng){
console.log(["setPos", latLng]);
setPos(latLng);
};
})();返回错误
this.set is not a function
http://maps.gstatic.com/intl/cs_ALL/mapfiles/api-3/2/0/main.js
Line 28为什么?谢谢
发布于 2010-08-23 01:40:05
初始google.maps.Marker.prototype.setPosition将在标记的作用域中调用,但是通过将其存储在局部变量中,您可以将其作用域更改为局部变量。
因此,函数没有其所需的this变量。您可以尝试通过使用dojo.hitch或读取this stackoverflow answer来修复此问题
此外,您还应该阅读有关作用域和闭包的this 。
发布于 2013-11-27 21:19:08
发布于 2016-02-13 02:17:08
您可以随时扩展原型并添加您自己的方法。
(function(){
google.maps.Marker.prototype.oldSetPosition =
google.maps.Marker.prototype.setPosition;
google.maps.Marker.prototype.setPosition = function(latLng){
console.log(["setPos", latLng]);
this.oldSetPosition(latLng);
};
})();这样就可以保持作用域的完整性。
https://stackoverflow.com/questions/3486146
复制相似问题