addCustomListener jsb 参数不正确

  • 版本 cocos2dx 3.17 js

在js当中,添加自定义事件监听器可以传3个参数,最后一个参数可用来传递运行时this,源码定义如下:

    addCustomListener: function (eventName, callback, target) {
        var listener = new cc._EventListenerCustom(eventName, callback, target);
        this.addListener(listener, 1);
        return listener;
    },

但这样写在 jsb (android) 中会报错无法执行:

JS: xxx.js:15:Error: js_cocos2dx_EventDispatcher_addCustomEventListener : wrong number of arguments: 3, was expecting 2

跟踪进 cpp 代码查看:

EventListenerCustom* EventDispatcher::addCustomEventListener(const std::string &eventName, const std::function<void(EventCustom*)>& callback)
{
    EventListenerCustom *listener = EventListenerCustom::create(eventName, callback);
    addEventListenerWithFixedPriority(listener, 1);
    return listener;
}

发现只能接受两个参数。