Yes, this is a tail call:
function(child) { child.add(n);
However, there is no tail recursion here because it is not a direct recursive call.
Also this.children.forEach(…) is the tail call in the add method.
However, the callback call inside the built-in forEach method is probably not optimized for the callback (and all but the last cannot be anyway). You can make it rewrite its function to
Blah.prototype.add = function(n) { "use strict"; this.total += n; let l = this.children.length; if (!l--) return; for (let i=0; i<l; i++) this.children[i].add(n); this.children[i].add(n);
Note that none of these tail calls will be optimized unless you also achieve return results.
Bergi source share