1
I was studying some jquery plugins and realized that to create html, the programmer wrote each line in an array and at the end used Join:
var tpl = [
'<div class="popover clockpicker-popover">',
'<div class="arrow"></div>',
'<div class="popover-title">',
'<span class="clockpicker-span-hours text-primary"></span>',
' : ',
'<span class="clockpicker-span-minutes"></span>',
'<span class="clockpicker-span-am-pm"></span>',
'</div>',
'<div class="popover-content">',
'<div class="clockpicker-plate">',
'<div class="clockpicker-canvas"></div>',
'<div class="clockpicker-dial clockpicker-hours"></div>',
'<div class="clockpicker-dial clockpicker-minutes clockpicker-dial-out"></div>',
'</div>',
'<span class="clockpicker-am-pm-block">',
'</span>',
'</div>',
'</div>'
].join('');
Someone, with experience, knows why to write this way, ie without using a string and concatenate each line?
var tpl = '<div class="popover clockpicker-popover">'+
'<div class="arrow"></div>'+
'<div class="popover-title">'+
'<span class="clockpicker-span-hours text-primary"></span>'+
' : '+
'<span class="clockpicker-span-minutes"></span>'+
'<span class="clockpicker-span-am-pm"></span>'+
'</div>'+
'<div class="popover-content">'+
'<div class="clockpicker-plate">'+
'<div class="clockpicker-canvas"></div>'+
'<div class="clockpicker-dial clockpicker-hours"></div>'+
'<div class="clockpicker-dial clockpicker-minutes clockpicker-dial-out"></div>'+
'</div>'+
'<span class="clockpicker-am-pm-block">'+
'</span>'+
'</div>'+
'</div>';
Define "better".
– Jéf Bueno
ECMA6 string template in the "programming" category is very good, but I don’t know how much performance and compatibility is still not as broad.
– BrTkCa
The doubt is about performance even, correct the "best"
– N. Dias
On Ecma6 you have the template string link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings
– cido18
I didn’t know this string template.
– N. Dias