It is necessary to call the function in the plugin options, it does not work

function randomInteger(min, max) { var rand = min + Math.random() * (max - min) rand = Math.round(rand); return rand; } .... bold : { title: CURLANG.bold, buttonHTML: '<span class="fonticon ve-tlb-bold1">\uE018</span>', excmd: 'bold', hotkey: 'ctrl+b', transform : { '<b='+randomInteger(1, 99999)+'>{SELTEXT}</b>':"[b]{SELTEXT}[/b]" } }, 
  • The object key is not an expression; concatenation, calculations, etc. are not supported. - user207618
  • @Other, do what? - Rammsteinik
  • @Other, in es2015 - supported - Grundy
  • @Rammsteinik, var o = { [prop]: "hey"} - Grundy
  • @Grundy, expression interpolation is not the key. Although yes, I forgot about this feature. - user207618

1 answer 1

As far as I know, the only way to get the object you want is to assemble it in steps:

 var bold = { title: CURLANG.bold, buttonHTML: '<span class="fonticon ve-tlb-bold1">\uE018</span>', excmd: 'bold', hotkey: 'ctrl+b', transform: {} } bold.transform['<b=' + randomInteger(1, 99999) + '>{SELTEXT}</b>'] = "[b]{SELTEXT}[/b]" 

.

A little bit later...

No, it turns out, you can write like this:

 function randomInteger(min, max) { var rand = min + Math.random() * (max - min) rand = Math.round(rand); return rand; } var bold = { title: 'CURLANG.bold', buttonHTML: '<span class="fonticon ve-tlb-bold1">\uE018</span>', excmd: 'bold', hotkey: 'ctrl+b', transform: { ['<b=' + randomInteger(1, 99999) + '>{SELTEXT}</b>']: "[b]{SELTEXT}[/b]" } } console.log(bold); 

https://jsfiddle.net/alexey_m_ukolov/wk4v77sn/1/

  • That's right, do not tell me how to insert this randomInteger (1, 99999) into 2 different places, like ['<b=' + rnd + '>{SELTEXT}</b=' + rnd + '>']: "[b]{SELTEXT}[/b]" to display the same values. To determine the variable did not work - Rammsteinik
  • @Rammsteinik, show the code in which you did not work - Alexey Ukolov