1

I have following object that does not fit into my coding screen:

{"hide(), show(), toggle(), fadeIn(), fadeOut(), fadeTo(), fadeToggle(), slideDown(), slideUp(), slideToggle(), animate(). Something different for text(), html(), and val() , attr() and load() ": "after each functions callback function can be executed?"},

Breaking it after the comma does not work. Neither \n is helping here.

How can I break the code so it would be easier to maintain it?

Jongware
  • 22,200
  • 8
  • 54
  • 100
Gilbert Cut
  • 113
  • 1
  • 12

2 Answers2

2

In ES6 you can use bracket notation to define an object key name like this:

const fooObj = {
  [fooName]: 'some nifty message'
}

Where fooName can be a variable holding a valid string. Mixing this with template literal strings you could do something like this:

const fooName = `
fee(),
fi(),
fo(),
fum(),
Homie I am not playing with you
`;
const fooObj = {
  [fooName]: 'some nifty message'
}

And that should work

Osman Cea
  • 1,467
  • 9
  • 18
-1

You can use word wrapping/line wrapping features of your IDE.

In Visual Studio Code:

Since v1.0 you can toggle word wrap:

  • with the new command editor.action.toggleWordWrap,
  • from the View
  • menu (View > Toggle Word Wrap), or using the ALT+Z keyboard shortcut (for Mac: ⌥+Z).

Source HERE

Or you can use javascript string concatenation with + sign like this to build the key string and use it in your object:

var key = "hide(), show(), toggle(), fadeIn(), fadeOut(), fadeTo(), "+
          "fadeToggle(), slideDown(), slideUp(), slideToggle(), "+
          "animate(). Something different for text(), html(), "+
          "and val() , attr() and load() "
var obj = { [key] : "after each functions callback function can be executed?"}

or if you prefer in one statement:

var obj = { ["hide(), show(), toggle(), fadeIn(), fadeOut(), fadeTo(), "+
          "fadeToggle(), slideDown(), slideUp(), slideToggle(), "+
          "animate(). Something different for text(), html(), "+
          "and val() , attr() and load() "] : 
          "after each functions callback function can be executed?"}
mike_t
  • 2,484
  • 2
  • 21
  • 39