julesrose julesrose - 23 days ago 7
Javascript Question

Arrowfunction inside of Object

Edit like suggested from str:

I want to create an object in a panel, and this object should contain a (or two) function(s). This Object will be handed over to a component (I am programming with angularjs, so I will hand it over via bindings) so I can configure my panel on the "clientcomponent" that opens that panel...

If I am trying to do that, IntelliJ gives the Error warning that a ',' is expected




I am trying to incorporate an arrowfunction inside of an js object.. but intellij doesn't like my approach.

I'm searching for sth like this:

this.api = {
showContent=(this.config)=> {
//do sth
}


Is that possible?

Answer

JS Object structure:

this.api = {
    showContent: true
};

Not to add arrow function try this

this.api = {
    showContent: this.config => {
        return true;
    }
};

Similar to old style

this.api = {
    showContent: function (config) {
        return true;
    } 
}