Objects are now considered types of class's mixed in traits
This is a consequence of ease.js' careful trait implementation that ensures that any mixed in trait retains its API in the same manner that interfaces and supertypes do.perfodd
parent
ee46fc2182
commit
451ec48a5c
|
@ -259,7 +259,8 @@ exports.isInstanceOf = function( type, instance )
|
|||
implemented = meta.implemented;
|
||||
i = implemented.length;
|
||||
|
||||
// check implemented interfaces
|
||||
// check implemented interfaces et. al. (other systems may make use of
|
||||
// this meta-attribute to provide references to types)
|
||||
while ( i-- )
|
||||
{
|
||||
if ( implemented[ i ] === type )
|
||||
|
|
12
lib/class.js
12
lib/class.js
|
@ -384,7 +384,17 @@ function createUse( base, traits )
|
|||
traits[ i ].__mixin( dfn );
|
||||
}
|
||||
|
||||
return extend.call( null, base, dfn );
|
||||
var C = extend.call( null, base, dfn ),
|
||||
meta = ClassBuilder.getMeta( C );
|
||||
|
||||
// add each trait to the list of implemented types so that the
|
||||
// class is considered to be of type T in traits
|
||||
for ( var i = 0, n = traits.length; i < n; i++ )
|
||||
{
|
||||
meta.implemented.push( traits[ i ] );
|
||||
}
|
||||
|
||||
return C;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -245,4 +245,26 @@ require( 'common' ).testCase(
|
|||
|
||||
this.fail( false, true, "Mixin must fail on conflict: " + desc );
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Traits in ease.js were designed in such a way that an object can be
|
||||
* considered to be a type of any of the traits that its class mixes in;
|
||||
* this is consistent with the concept of interfaces and provides a very
|
||||
* simple and intuitive type system.
|
||||
*/
|
||||
'A class is considered to be a type of each used trait': function()
|
||||
{
|
||||
var Ta = this.Sut( {} ),
|
||||
Tb = this.Sut( {} ),
|
||||
Tc = this.Sut( {} ),
|
||||
o = this.Class.use( Ta, Tb ).extend( {} )();
|
||||
|
||||
// these two were mixed in
|
||||
this.assertOk( this.Class.isA( Ta, o ) );
|
||||
this.assertOk( this.Class.isA( Tb, o ) );
|
||||
|
||||
// this one was not
|
||||
this.assertOk( this.Class.isA( Tc, o ) === false );
|
||||
},
|
||||
} );
|
||||
|
|
|
@ -56,4 +56,19 @@ require( 'common' ).testCase(
|
|||
C().foo();
|
||||
this.assertOk( called );
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Just as subtypes inherit the same polymorphisms with respect to
|
||||
* interfaces, so too should subtypes inherit supertypes' mixed in
|
||||
* traits' types.
|
||||
*/
|
||||
'Subtype has same polymorphic qualities of parent mixins': function()
|
||||
{
|
||||
var T = this.Sut( {} ),
|
||||
o = this.Class.use( T ).extend( {} ).extend( {} )();
|
||||
|
||||
// o's supertype mixes in T
|
||||
this.assertOk( this.Class.isA( T, o ) );
|
||||
},
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue