0

After the first click I want to change my .on() Method.

mySurface.on("touchstart",function(){
      doSomething();       
})

and after the first click I want to change it for example to:

mySurface.on("touchstart",function(){
      doSomethingDifferent();       
})

How can I overwrite my .on Method?

user2988098
  • 81
  • 1
  • 6

1 Answers1

0

Overwriting the .on() method is not really needed in your case here.

Here is one way to handle your use case.

  var doSomethingElse = function(event) {
    console.log('doSomethingElse', event);
    console.log('mySurface', this);
  };

  var doSomething = function(event) {
    console.log('doSomething', event);
    console.log('mySurface', this);
    func = doSomethingElse;
  };

  var func = doSomething;

  mySurface.on("touchstart",function(event){
    func.call(this, event);       
  });
talves
  • 13,993
  • 5
  • 40
  • 63