I have a function in javascript
var fn = function(){
var obj = {result: true};
return obj.result;
};
I have access to the function, but I need to get the inner obj
. Is there a way to do that?
EDIT: Thanks to the answers below, I have managed to come up with a solution. https://stackoverflow.com/users/1447675/nina-scholz 's answer was the closest, so I marked it as the solution.
var f2 = function fn(){
fn.obj = {result: true};
return fn.obj.result;
};
A client of this function can use it like the following :-
var myFunction = f2;
The function must be called though, to access the inner variables
myFunction();
After that one can do the following.
console.log(myfunction.obj);
This seems to be working. I would, however like to know if this is a good practice.
you can access
obj
when you make it public.