util.propParse() now ignores instance prototype properties
parent
f2baf82100
commit
2c49e9719f
|
@ -142,6 +142,12 @@ exports.propParse = function( data, options )
|
||||||
// dealing with (in the classic OO sense)
|
// dealing with (in the classic OO sense)
|
||||||
for ( prop in data )
|
for ( prop in data )
|
||||||
{
|
{
|
||||||
|
// ignore properties of instance prototypes
|
||||||
|
if ( !( data.hasOwnProperty( prop ) ) )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var value = data[ prop ],
|
var value = data[ prop ],
|
||||||
getter = ( ( getset ) ? data.__lookupGetter__( prop ) : null ),
|
getter = ( ( getset ) ? data.__lookupGetter__( prop ) : null ),
|
||||||
setter = ( ( getset ) ? data.__lookupSetter__( prop ) : null );
|
setter = ( ( getset ) ? data.__lookupSetter__( prop ) : null );
|
||||||
|
|
|
@ -146,3 +146,24 @@ assert.equal(
|
||||||
"Property parser supports passing each property to the provided function"
|
"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"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue