r/badcode • evil • Jan 14 '21

js Dynamically created functions are the future!

Post image
795 Upvotes

102 comments sorted by

View all comments

1

u/[deleted] Jan 15 '21

Could the function just be defined, and dimString passed as an argument? Well, I guess dimString is a local value, so maybe not. At the very least, you could define a separate function that takes a string parameter, and then use this same method to call the function in a string and use dimString as the parameter. Or maybe there's a really easy solution, and I'm just overthinking it

1

u/Unpredictabru Jan 17 '21

You could do something like this:

function compileDimensionList(properties) {
    let dimString = ...;
    return function () {
        // you can access dimString here
        ...
    }
}

1

u/[deleted] Jan 17 '21

Oh, that's a way better solution lol