1
0
Fork 0

util.propParse() now ignores instance prototype properties

closure/master
Mike Gerwitz 2010-12-18 07:07:27 -05:00
parent f2baf82100
commit 2c49e9719f
2 changed files with 27 additions and 0 deletions

View File

@ -142,6 +142,12 @@ exports.propParse = function( data, options )
// dealing with (in the classic OO sense)
for ( prop in data )
{
// ignore properties of instance prototypes
if ( !( data.hasOwnProperty( prop ) ) )
{
continue;
}
var value = data[ prop ],
getter = ( ( getset ) ? data.__lookupGetter__( prop ) : null ),
setter = ( ( getset ) ? data.__lookupSetter__( prop ) : null );

View File

@ -146,3 +146,24 @@ assert.equal(
"Property parser supports passing each property to the provided function"
);
var Foo = function() {};
Foo.prototype.one = 1;
var instance = new Foo();
instance.two = 2;
var count = 0;
util.propParse( instance, {
each: function()
{
count++;
},
} );
assert.equal(
count,
1,
"propParse should ignore prototype properties of instances"
);