JSFiddle - React, Tailwind, and code Playground
HTML
<div id="log">
</div>
JavaScript
var log = document.querySelector("#log");
function formatFull() {
return `${this.title}:\n\tдоступно ${this.available} шт.\n\tв резерве ${this.holded} шт.`;
}
function formatLite() {
return `${this.title} (${this.available} + ${this.holded})`;
}
function show(format) {
log.innerHTML += `<p>${format()}<p>`;
}
function showItems(items, formatter) {
for (let item of items) {
show.call(item, formatter.bind(item));
}
}
var items = [{ title: "11", available: 1, holded: 2 }, { title: "22", available: 3, holded: 4 }];
showItems(items, formatLite);
showItems(items, formatFull);