How to extend CCMenuItem in the JS binding?

Hi guys,

Is there any ability to extend MenuItem in the JS? For now I haven’t found a way to call “initWithTarget”…
Sample code would be great.

Thanks.

Hello,

I had the same problem with MenuItemFont, we can’t use the .initWithXXX() methods.
You just have to use the .create() method with parameters. In my case, it’s cc.MenuItemFont.create(<Label>, <selector>);

But if you want to extend MenuItem, you must use .extend() method, like this:

var MyCustomMenuItem = cc.MenuItem.extend({
    ctor: function(param) {        
        cc.associateWithNative( this, cc.MenuItem ); // Very important, needed for JSB compatibility
        // some code
    },

    initWithXXX: function(iDontKnow) { // Your init function, should be called later than the constructor        
        this._super(iDontKnow); // calls the parent method
        // some other code
    }
}

I’m not sure at 100% for the use of the IDontKnow param.

When you want to use your custom menu item:

var myMenuItem = MyCustomMenuItem(param);
myMenuItem.initWithXXX(Dunno)