Added tests to ensure constructor is properly applied to subtypes
parent
d5f37f294e
commit
f58586fc94
|
@ -175,6 +175,9 @@ var extend = ( function( extending )
|
|||
// call the constructor, if one was provided
|
||||
if ( this.__construct instanceof Function )
|
||||
{
|
||||
// note that since 'this' refers to the new class (even
|
||||
// subtypes), and since we're using apply with 'this', the
|
||||
// constructor will be applied to subtypes without a problem
|
||||
this.__construct.apply( this, arguments );
|
||||
}
|
||||
};
|
||||
|
|
|
@ -94,3 +94,36 @@ for ( var i = 0, len = args.length; i < len; i++ )
|
|||
"Arguments should be passed to the constructor: " + i
|
||||
);
|
||||
}
|
||||
|
||||
var SubFoo = Foo.extend(
|
||||
{
|
||||
args: [ 'should', 'be', 'overwritten' ],
|
||||
} );
|
||||
|
||||
construct_count = 0;
|
||||
construct_context = null;
|
||||
|
||||
var args2 = [ 'fried', 'pickle' ],
|
||||
subobj = new SubFoo( args2[ 0 ], args2[ 1 ] );
|
||||
|
||||
assert.equal(
|
||||
construct_count,
|
||||
1,
|
||||
"Parent constructor should be called for subtype if not overridden"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
construct_context,
|
||||
subobj,
|
||||
"Parent constructor is run in context of the subtype"
|
||||
);
|
||||
|
||||
// this should be implied by the previous test, but let's add it for some peace
|
||||
// of mind
|
||||
assert.ok(
|
||||
( ( subobj.args[ 0 ] === args2[ 0 ] )
|
||||
&& ( subobj.args[ 1 ] == args2[ 1 ] )
|
||||
),
|
||||
"Parent constructor sets values on subtype"
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in New Issue