PDA

View Full Version : this.hasOwnProperty problem



Bensiu
20 Jan 2011, 11:46 AM
I am looking for seting up properties in object own setValue method:


O_level_1 = Ext.extend ( Ext.util.Observable, {
PropA : null,
PropB : null,

constructor: function ( ) {
O_level_1.superclass.constructor.call ( this );
},

setValue: function ( name, value ) {
if ( this.hasOwnProperty ( name ) ) {
if ( window.console ) console.log ('setValue level 1 IN : '+name+':'+value);
else alert ('setValue level 1 IN : '+name+':'+value);
this[name] = value;
}
if ( window.console ) console.log ('setValue level 1 OUT : '+name+':'+value);
else alert ('setValue level 1 OUT : '+name+':'+value);
}
} );
O_level_2 = Ext.extend ( O_level_1, {

PropC : null,
PropD : null,
constructor: function ( ) {
O_level_2.superclass.constructor.call ( this );
},

setValue: function ( name, value ) {
O_level_2.superclass.setValue ( name, value );
if ( this.hasOwnProperty ( name ) ) {
if ( window.console ) console.log ('setValue level 2 IN : '+name+':'+value);
else alert ('setValue level 2 IN : '+name+':'+value);
this[name] = value;
}
if ( window.console ) console.log ('setValue level 2 OUT : '+name+':'+value);
else alert ('setValue level 2 OUT : '+name+':'+value);
}

} );

var temp = new O_level_2 ( );
temp.setValue ( 'PropA', 1234 ); // good result level 1 IN, level 1 OUT, level 2 OUT
temp.setValue ( 'PropD', 1234 ); // does not go to level 2 IN but should and expected


Does someone know the solution? Why level 2 can not access to seting method ?

hendricd
21 Jan 2011, 7:31 AM
Missing one important part : context


O_level_2.superclass.setValue.call (this, name, value );