79529507

Date: 2025-03-23 18:43:24
Score: 0.5
Natty:
Report link

why use JSON to store functions? use JS at this point. you can even convert it to some sorta codegen tool by replacing ;( ) wrapper with something like export default( ) and have a valid javascript file that your lsp can read and give you insight about.

function jsave(obj) {
    if (typeof obj !== "object") return `${eval(obj)}`
    let result = "{ "
    for (const [key, val] of Object.entries(obj)) 
        result += `${key}: ${jsave(val)}, `
    result += " }"
    return result
}

const obj = { a: 9, utils: { double: t => t * 2 } }

const file = `;(${ jsave(obj) })`

console.log(file)

const loaded = eval(file)

console.log(obj.utils.double(3))
console.log(loaded.utils.double(3))

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): why use
  • Low reputation (0.5):
Posted by: Vagif VALIYEV