function Cons()
{
this.a = "variable a";
this.callme = function callme()
{
var str = "";
for(var x in this)
{
str += this[x] + " ";
}
return str;
}
}
var obj = new Cons();
obj.c = "variable 2";
var fin = obj.callme();
document.write(fin);
I want to have a function inside the object so that when it is called it can return a string consisting of the values of every member. Here in this case a and c. Now what happens, everything inside the function i mean the code is printed inside the browser instead of just returning the value of str.
What i understood is that this["callme"] part in the for-in loop returns the whole code as its also a variable. So how to solve this problem.
I am new to javascript please help me.