Dojo: how to use own onMove event (overwrite)

2020-05-08 18:57发布

问题:

In docs it was said that:

onMove(mover, leftTop, e) called during every move notification; should actually move the node; can be overwritten.

but no example how to overwrite it (onMove). Can somebody throw several lines of code to show how it works?

Thanks.

回答1:

You don't point out which dojo JavaScript class that the onMove function belongs to. However, you have a couple of generic ways to override functions that also applies in your case.

1) Create a new subclass using dojo.declare.

Suppose the JavaScript class name is myClass, you can use

dojo.declare('anotherClass', myClass, {
    onMove : function(mover, leftTop, e) {}   
});

2) Change the class's prototype using dojo.extend.

dojo.extend(myClass, {
    onMove : function(mover, leftTop, e) {}         
});

If you only want to override the function for a single instance, set the property directly.

var obj = new myClass();
obj.onMove = function() {};