“Converting” would probably be a bit misleading since ES5 code is always valid ES6 code as well… however a few minor ES6-specific improvements would be possible I think. :-)
(function() {
// Within this function, `obj` and `target` aren't supposed
// to be reassigned, so you might declare them as constants
// to ensure this (and make it immediately clear to the reader)
const obj = breakFastMenu.food;
// Not ES6, but much shorter anyway... ^^
const target = document.body;
// You can iterate over the elements of an array (or any iterable,
// for that matter) with `for ... of` now; `item` as declared with `let`
// will only be available within the scope of that loop
for (let item of obj) {
// The destructuring assignment is just a very nice shorthand :-)
var {name, price, description, calories} = item;
target.innerHTML += '<p>' + name + '</p>';
target.innerHTML += '<p>' + price + '</p>';
target.innerHTML += '<p>' + description + '</p>';
target.innerHTML += '<p>' + calories + '</p>';
}
})();
Possibly because people coming from a classical OOP background will use them and never even realise that all the other ways of creating classes in a prototyping OOP language like JavaScript even exist.
Although I do expect expert JavaScript developers to understand how object creation and inheritance works, I think that most of the time, we don’t actually need to know or care. I especially came to this realization when using Python, and I discovered that Python’s class and inheritance mechanism works almost exactly the same as JavaScript’s. Python “classes” are runtime objects that you can monkey patch, and inheritance also happens at runtime by delegation. Except the Python community doesn’t make a big fuss about it, nor did that knowledge change how I wrote and organized the program, because the truth is the vast majority of the time we don’t need to know or care how the class and inheritance mechanism works under the hood. We only need to know the abstract behavior is provides.