I have a contrived example in javascript to explain what I am trying to do:
I have an object:
var Item = {
_first = undefined,
_second = undefined,
whole = putTogether()
};
function putTogether() {
if (_first && _second)
return _first + '_' + _second;
return '{ Invalid Values }';
}
I am trying to be able to access Item.whole
as a property. Is there a way I can do this so that putTogether
is evaluated every time it is accessed, rather than initially when the object is created?
I am aware I can define an anonymous function for Item.whole
, but I am specifically trying to construct it so that it can be referenced as a value rather than a function.