Like Daniel pointed out, you could build the string on your way out like this:
function myFormat(d) {
let result = '<table cellpadding="5" cellspacing="0" border="0">';
if (name){
result += '<tr>' + '<td>Name:</td>' + '<td>' + d.name + '</td>' + '</tr>';
}
if (place){
result += '<tr>' + '<td>Place:</td>' + '<td>' + d.place + '</td>' + '</tr>';
}
if (date){
result += '<tr>' + '<td>Date:</td>' + '<td>' + d.date + '</td>' + '</tr>';
}
result += '</table>';
return result;
}
Html elements could be combined together as well to make it simpler like this:
'<tr><td>Place:</td><td>' + d.name + '</td></tr>'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…