const x = {};
x.y = function y() {
console.log("hello");
y();
};
x.y();
as written, calling x.y()
will infinitely recurse. this is particularly cumbersome if there is a y
in the outer scope as it is now unreachable:
const x = {};
x.y = function y() {
console.log("hello");
y();
};
function y() {
console.log("world");
}
x.y();
the only way to avoid it is like so:
x.y = function () {
console.log("hello");
y();
};
Object.defineProperty(x.y, "name", { value: "y" });
curious on other's thoughts on how they handle this, or run into it often.