Eheka Pytyvõha

Emboyke pytyvõha apovai. Ndorojeruremo’ãi ehenói térã eñe’ẽmondóvo pumbyrýpe ha emoherakuãvo marandu nemba’etéva. Emombe’u tembiapo imarãkuaáva ko “Marandu iñañáva” rupive.

Kuaave

JavaScript problem - properties assigned by setters are always undefined

  • 2 Mbohovái
  • 2 oguereko ko apañuãi
  • 5 Hecha
  • Mbohovái ipaháva jfd34

more options

Consider this JavaScript code:

function foo(x) {
    var obj = { 
        set a(val) { document.write('Setting obj.a to ' + val + '\r\n'); }
    };
   
    obj.a = x;
    return obj.a + 2;
}
var n = foo(3);

The value of n will be NaN instead of the expected 5.

Is this a bug in Firefox or there is something wrong with the JavaScript code itself?

Consider this JavaScript code: function foo(x) { var obj = { set a(val) { document.write('Setting obj.a to ' + val + '\r\n'); } }; obj.a = x; return obj.a + 2; } var n = foo(3); The value of n will be NaN instead of the expected 5. Is this a bug in Firefox or there is something wrong with the JavaScript code itself?

Moambuepyre jfd34 rupive

Opaite Mbohovái (2)

more options

This at least works.

function foo(x) {
var obj = { set aValue(val){ this.a=val; } };
obj.a = x;
return (obj.a + 2);
}
var n = foo(3);
alert(n);
more options

It is obvious why the code given by cor-el will work. The setter function is not called at all. It is similar to this:

function foo(x) {
    var obj = {};
    obj.a = x;
    return (obj.a + 2);
}
var n = foo(3);
alert(n);

I want something which sets a property of an object using a setter function, and then retreives the value of that property.