I've been reading SICP and one concept they teach is abstracting certain details away from the user. I'm trying to build a set of subfunctions that return object paths that can be passed as an argument in a higher order function. The problem I found was that most of the time javascript will resolve the object path to whatever value it's referencing before passing it to the higher order function. With some help I managed to cobble together this crude solution but I was hoping theres a better way.
let object = {
prop1: "sth",
prop2: "sthelse"
}
function getPath(whichProp) {
return `object["${whichProp}"]`};
function deleteProp(aPath) {
console.log(aPath) //prints object["prop1"]
eval(`delete ${aPath}`);
console.log(object) // {prop2: sthelse}
}
deleteProp(getPath("prop1"))
Is there some method of message passing that can be used here? Having the function resolve to a function calling it's argument with itself as that functions' argument. Hope that's coherent, thanks in advance.