Can't call function in touch event listener function ? on cocos2d-js-html5

I have this code.

if (cc.sys.capabilities.hasOwnProperty('touches')) {
            cc.eventManager.addListener({
                event: cc.EventListener.TOUCH_ALL_AT_ONCE,
                onTouchesBegan:function(touches, event) {
                    for (var i = 0; i < touches.length; i++) {
                        x = touches[i].getLocationX();
                        y = touches[i].getLocationY();
                        if (any condition) {
                            this.exampleFunc();
                        }
                    }
                }
            }, this);
 }

This error returned => Uncaught TypeError: this.exampleFunc is not a function.
I don’t understand this error. exampleFunc is defined. Like this

exampleFunc:function () {
        cc.log("this is example function");
}

is cant call function in TouchEventListener guys help me :smiley: :smiley: :blush:

You can refer to http://cocos2d-x.org/wiki/EventManager_Mechanism.

Hello,

Get a current event target inside touchBegan function.

 var target = event.getCurrentTarget();

Call exampleFunc using obtained target.

target.exampleFunc();

For more detailed information you can refer below link

Thanks.

Thanks all. I solved the problem. Important

.bind(this)

if (cc.sys.capabilities.hasOwnProperty('touches')) {
            cc.eventManager.addListener({
                event: cc.EventListener.TOUCH_ALL_AT_ONCE,
                onTouchesBegan:function(touches, event) {
                    for (var i = 0; i < touches.length; i++) {
                        x = touches[i].getLocationX();
                        y = touches[i].getLocationY();
                        if (any condition) {
                            this.exampleFunc();
                        }
                    }
                }.bind(this);
            }, this);
 }

Yes or just get a refrence to “this” before the function so
var self = this
then inside the touch listener use
self.exampleFunc();