Previous: , 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

Figure 4.4: Type checking with prototypal subtypes of GNU ease.js classes

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
Part of the GNU Project

Copyright © 2011, 2012, 2013, 2014, 2015, 2016 Free Software Foundation, Inc.

"GNU Inside!" Page Fold licensed under CC-BY-SA 2.0; incorporates "A Big GNU Head".

The source code of this website is available in the website branch of the Git repository.

Authored by Mike Gerwitz

AltStyle によって変換されたページ (->オリジナル) /