From df2943b5a1fbc06122710dac9132c5ce9e8d462b Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Sun, 6 Mar 2011 22:16:50 -0500 Subject: [PATCH] Replaced __define[GS]etter__ with defineProperty for prop proxy --- lib/propobj.js | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/propobj.js b/lib/propobj.js index a36ff01..8a1b744 100644 --- a/lib/propobj.js +++ b/lib/propobj.js @@ -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 ) - { - base[ prop ] = 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() - { - return base[ prop ]; + get: function() + { + return base[ prop ]; + }, + + enumerable: true, } ); } ).call( null, prop ); }