JSFiddle - React, Tailwind, and code Playground
JavaScript
function createSomething(init, aaa) {
function privateMethod(param) {
return init[param]; //assuming this is more complicated, how can you test it?
}
function getData() {
return init.data;
}
function getValue(name) {
if (name === "privateNode" || typeof name !== "string") {
return "permissionDenied";
}
return privateMethod(name);
}
// ----------------------------------
if(aaa) return privateMethod;
// ----------------------------------
return {
getData : getData,
getValue: getValue
};
}
var something = createSomething({
privateNode : "allmysecrets",
id : "1234",
data : {
stuff : "32t97gfhw3hg4"
}
}, 1); // passing extra arg to get method
console.log(
something('id'),
something('privateNode')
) // 1234 allmysecrets