javascript private method reference inside immediately invoked function -


this javascript code needs take in sentence, extract first word, , call function named first word, nothing if no function present word. not compiling. idea why , how fix it?
i.e. how can pass parameters function?

refactor = (function () {    const john = function (description) {     console.log(description);   };    const factoring = {     'john': john(description) // <--- description not defined ---    };    return object.freeze({     'byname': function (description) {  // calls correct private method if present       let name = description.match(/(\s+)\s/)[1];       if (name in factoring) factoring[name](description);     }   }); }()); 

desc not defined. either define desc , give value (const desc = "some random string") or replace desc value ('john': john("some random string")).


Comments