1
0
Fork 0

Replaced __define[GS]etter__ with defineProperty for prop proxy

closure/master
Mike Gerwitz 2011-03-06 22:16:50 -05:00
parent 3651e31d20
commit df2943b5a1
1 changed files with 14 additions and 9 deletions

View File

@ -90,18 +90,23 @@ exports.createPropProxy = function( base, dest, props )
( function( prop )
{
// just in case it's already defined, so we don't throw an error
dest[ prop ] = undefined;
// public properties, when set internally, must forward to the
// actual variable
dest.__defineSetter__( prop, function( val )
Object.defineProperty( dest, prop, {
set: function( val )
{
base[ prop ] = val;
} );
},
// since we're defining a setter, we'll need to define a getter
// to return the value, or we'll simply return undefined
dest.__defineGetter__( prop, function()
get: function()
{
return base[ prop ];
},
enumerable: true,
} );
} ).call( null, prop );
}