访问函数中的Polymer方法 [英] Getting access to a Polymer method inside a function
本文介绍了访问函数中的Polymer方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用聚合物Google Map元素,并且在向地图添加事件侦听器时遇到了问题。
I use the Polymer Google Map element and I've faced with a problem while adding an event listener to the map.
* blah blah blah *
ready: function () {
this.map.addEventListener('google-map-rightclick', this._rightClickOnMap);
},
test: function () {
console.log(1);
},
_rightClickOnMap: function (event) {
this.test();
}
* blah blah blah *
我试图绑定这个给列表员,但JS扔我错误
I've tried to bind this to the listner but JS throw me the error
this.map.addEventListener('google-map-rightclick', this._rightClickOnMap).bind(this);
推荐答案
您需要在函数上调用bind而不是
$ b
You need to call bind on the function and not on the event listener.
this.map.addEventListener('google-map-rightclick', this._rightClickOnMap.bind(this));
这篇关于访问函数中的Polymer方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文