I am a newbie in JavaScript and so don’t really understand its object model, but as I understood I have to do something like.
function set_test(text) { this['test'] = text; };
a = {};
text = 'ok';
a.prototype.ok = set_test(text);
alert(a['test']); #Should be 'ok'
text = 'fail';
a.ok;
alert(a['test']); #Should be 'ok'
Can somebody say what’s wrong here?
Objects don’t have a prototype by default, and
a.prototype.ok = set_test(text);would makeokequal to the return value ofset_test()which isundefined.Try doing it this way instead: