Let's say I've got two functions a
and b
that I want to be visible within a given functional scope. They share some common functionality, so I factor the common code out into a third method called support
.
support
needs to be callable by both a
and b
, but I don't want it to be visible to other methods at this scope. Is this possible?
// Some scope; maybe global, maybe another function
function a() {
let res = support()
res.name = "a"
return res
}
function b() {
let res = support()
res.name = "b"
return res
}
function support() {
return {"foo": "bar", "name": "support"}
}
I came up with an idea while writing that I'll post as an answer, but it's not quite what I'm looking for, as a
and b
become function expressions, rather than behaving like regular function declarations (if I'm using the right terminology).