I have a problem with return a value from an object.
my object looks like this.
function XYZ(date, startT) { var _date=date; var _startT=startT; this.get_date = function() { return _date; }; this.set_date = function(value) { _date=value; }; this.get_startT = function() { return _startT; }; this.set_startT = function(value) { _startT=value; }; this.toString() return (_date + " " _startT); }
then i create an Array like this
jsData[0] =new XYZ("2012-11-11","8:00"); jsData[1] = new XYZ("2012-03-03","8:00");
when i want to use get_date method it didn’t return me the value but the get_startT method works fine.
When i show object with .toString method it also show me full object
Please help.
It works if you fix all the syntax errors:
Output:
Live Copy | Source
Other than obvious typos, here’s what I did:
Put
{and}around the function body.Removed the
this.toString()which was non-functional (a no-op, as you didn’t store the result anywhere).Removed the return at the end, because returning a string primitive out of a constructor function is another no-op.
Declared
jsData.Initialized
jsData.