Previous: Prototypally Extending Classes, Up: Interoperability [Contents]
4.3 Interoperable Polymorphism
GNU ease.js encourages polymorphism through type checking. In the case of prototypal subtyping, type checks will work as expected:
var Foo = Class( {} ); function SubFoo() {}; SubFoo.prototype = Foo.asPrototype(); SubFoo.constructor = Foo; var SubSubFoo = Class.extend( SubFoo, {} ); // vanilla ECMAScript ( new Foo() ) instanceof Foo; // true ( new Subfoo() ) instanceof Foo; // true ( new SubSubFoo() ) instanceof Foo; // true ( new SubSubFoo() ) instanceof SubFoo; // true // GNU ease.js Class.isA( Foo, ( new Foo() ) ); // true Class.isA( Foo, ( new SubFoo() ) ); // true Class.isA( Foo, ( new SubSubFoo() ) ); // true Class.isA( SubFoo, ( new SubSubFoo() ) ); // true
Plainly—this means that prototypes that perform type checking for polymorphism will accept GNU ease.js classes and vice versa. But this is not the only form of type checking that ease.js supports.
This is the simplest type of polymorphism and is directly compatible with ECMAScript’s prototypal mode. However, GNU ease.js offers other features that are alien to ECMAScript on its own.
• Interface Interop: | Using GNU ease.js interfaces in conjunction with vanilla ECMAScript |