如何访问下面JavaScript对象的"ondrag"方法?

How to access the "ondrag" method of the following JavaScript object?

对象是这样的:

这就是我访问它的方式:console.log(this)this 输出 Directive 对象)。

如何调用此对象的 ondrag 事件?

我试过这个:

this.el('ondrag', function(event) {
  console.log(event)
})

但是我得到了:

caught TypeError: this.el is not a function

访问 ondrag 活动的正确方法是什么?

This.elreturns一个DOMElement object which inherits from Event arget.

所以你可以使用addEventListener():

this.el.addEventListener('drag', function (event) {
  //....
})

或者,按照评论中 "mrahhal" 的建议,分配它:

this.el.ondrag = function(event) {
  // ...
}