Classical Object-Oriented
JavaScript Framework

Download
Released:

GNU ease.js is a Classical Object-Oriented framework for JavaScript, intended to eliminate boilerplate code and “ease” the transition into JavaScript from other Object-Oriented languages. Features include:

GNU ease.js is a framework, not a compiler. It may be used wherever JavaScript may be used, and supports all major browsers; ease.js also provides support for older, pre-ES5 environments by gracefully degrading features (such as visibility support) while remaining functionally consistent.

This project is part of the GNU Project.

Simple and Intuitive Class Definitions

Class definitions closely resemble the familiar syntax of languages like Java and PHP.

  

Classes can be anonymous or named, the latter being more useful for debugging. Since classes may be anonymous, constructors are styled after PHP.

  

Classes can be instantiated with or without the new keyword. Omission aids in concise method chaining and the use of temporary instances.

  var inst = Foo( "John Doe" );
  var inst = new Foo( "John Doe" );

  // temporary instance
  Foo( "John Doe" ).sayHello();
→ Read more in manual

Classical Inheritance

Classes can be extended to create subtypes. Like C++, methods are not virtual by default. In Java terminology, all methods are final by default. Multiple inheritance, like Java, is unsupported (see Interfaces).

  

Alternatively, if creating an anonymous subtype, the supertype's extend() method may be used.

  var SturdyCow = Cow.extend( { /*...*/ } );

Type checks for polymorphic methods may be performed with Class.isA(), which is recommended in place of instanceof.

  

To prevent a class from being extended, FinalClass may be used.

  
→ Read more in manual

Abstract Classes and Methods

If a class contains abstract members, it must be declared as an AbstractClass. Abstract methods must be overridden by subtypes and are implicitly virtual.

  
→ Read more in manual

Interfaces

ease.js supports the Java concept of Interfaces, which act much like abstract classes with no implementation. Each method is implicitly abstract. Properties cannot be defined on interfaces.

  

Concrete classes may implement one or more interfaces. If a concrete class does not provide a concrete implementation for every method defined on the interface, it must be declared an AbstractClass.

  

Polymorphic methods may check whether a given object implements a certain interface.

  
→ Read more in manual

Access Modifiers

All three common access modifiers—public, protected and private—are supported, but enforced only in ECMAScript 5 and later environments.

  

In the above example, the database connection remains encapsulated within DatabaseRecord. Subtypes are able to query and escape strings and external callers are able to retrieve a name for a given id. Attempting to access a private or protected member externally will result in an error. Attempting to access a private member from within a subtype will result in an error.

Alternatively, a more concise style may be used, which is more natural to users of JavaScript's native prototype model:

  
→ Read more in manual

Static and Constant Members

Static members are bound to the class itself, rather than a particular instance. Constants are immutable static members (unlike languages like PHP, they may use any access modifier). In order to support both pre- and post-ECMAScript 5 environments, the syntax requires use of a static accessor method—$().

  
→ Read more in manual

Traits As Mixins

Trait support was introduced in celebration of becoming a GNU project. It is currently under development and has not yet been finalized, but has been included in each GNU ease.js release since v0.2.0, and is stable.

Documentation will be available once some final details are finalized. Until that time, the test cases provide extensive examples and rationale. The following posts also summarize some of the features: