2011-11-23 20:08:26 -05:00
|
|
|
<p>
|
2013-12-22 23:46:04 -05:00
|
|
|
<span class="bigemph">GNU ease.js is a Classical Object-Oriented framework for
|
2012-05-05 14:09:27 -04:00
|
|
|
JavaScript,</span> intended to eliminate boilerplate code and
|
|
|
|
“ease” the transition into JavaScript from other Object-Oriented
|
|
|
|
languages. Features include:
|
2011-11-23 20:08:26 -05:00
|
|
|
</p>
|
|
|
|
|
2012-05-05 23:58:42 -04:00
|
|
|
<a href="download.html" class="download btn large go">
|
|
|
|
Download v<!--%curver-->
|
2012-05-07 00:40:29 -04:00
|
|
|
<div class="note">(Released: <!--%curver-date-->)</div>
|
2012-05-05 23:58:42 -04:00
|
|
|
</a>
|
|
|
|
|
2012-01-08 16:14:38 -05:00
|
|
|
<ul class="features">
|
2012-05-05 14:09:27 -04:00
|
|
|
<li><a href="#class-dfn">Simple and intuitive class definitions</a></li>
|
|
|
|
<li><a href="#inheritance">Classical inheritance</a></li>
|
|
|
|
<li><a href="#abstract">Abstract classes and methods</a></li>
|
|
|
|
<li><a href="#interfaces">Interfaces</a></li>
|
2013-12-22 23:46:04 -05:00
|
|
|
<li>
|
|
|
|
<a href="#access-modifiers">
|
2012-05-05 14:09:27 -04:00
|
|
|
Access modifiers (public, protected and private)
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
<li><a href="#static">Static and constant members</a></li>
|
2011-11-23 20:08:26 -05:00
|
|
|
</ul>
|
|
|
|
|
2012-01-08 16:14:38 -05:00
|
|
|
<p class="info">
|
2012-05-05 14:09:27 -04:00
|
|
|
ease.js is a framework, not a compiler. It may be used wherever JavaScript may
|
|
|
|
be used, including with other compilers/parsers. ease.js also provides
|
|
|
|
support for older, pre-ES5 environments by gracefully degrading features (such
|
|
|
|
as visibility support), but remaining functionally consistent.
|
2011-11-23 20:08:26 -05:00
|
|
|
</p>
|
2012-05-05 14:09:27 -04:00
|
|
|
|
|
|
|
<h3 id="class-dfn" class="bigemph">
|
|
|
|
Simple and Intuitive Class Definitions
|
|
|
|
<span class="anchor"><a href="#class-dfn">¶</a></span>
|
|
|
|
</h3>
|
|
|
|
<p>
|
2012-05-07 17:19:37 -04:00
|
|
|
Class definitions closely resemble the familiar syntax of languages like Java
|
|
|
|
and PHP.
|
2012-05-05 14:09:27 -04:00
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/class.js -->
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>
|
2012-05-06 23:43:54 -04:00
|
|
|
Classes can be
|
|
|
|
<a href="manual/Anonymous-vs_002e-Named-Classes.html" class="man">anonymous or
|
|
|
|
named</a>, the latter being more useful for debugging. Since classes may be
|
|
|
|
anonymous, constructors are <a
|
|
|
|
href="manual/Constructor-Implementation.html" class="man">styled after
|
|
|
|
PHP</a>.
|
2012-05-05 14:09:27 -04:00
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/class-anon.js -->
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Classes can be instantiated with or without the <tt>new</tt> keyword. Omission
|
2012-05-06 23:43:54 -04:00
|
|
|
aids in concise method chaining and the use of
|
|
|
|
<a href="manual/Temporary-Instances.html" class="man">temporary instances</a>.
|
2012-05-05 14:09:27 -04:00
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
var inst = Foo( "John Doe" );
|
|
|
|
var inst = new Foo( "John Doe" );
|
|
|
|
|
2012-05-06 23:43:54 -04:00
|
|
|
// temporary instance
|
2012-05-05 14:09:27 -04:00
|
|
|
Foo( "John Doe" ).sayHello();
|
|
|
|
</pre>
|
2012-05-06 23:08:21 -04:00
|
|
|
<a href="manual/Defining-Classes.html">→ Read more in manual</a>
|
2012-05-05 22:42:21 -04:00
|
|
|
<a href="#" class="top">↑</a>
|
2012-05-05 14:09:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
<h3 id="inheritance" class="bigemph">
|
|
|
|
Classical Inheritance
|
|
|
|
<span class="anchor"><a href="#inheritance">¶</a></span>
|
|
|
|
</h3>
|
|
|
|
<p>
|
|
|
|
Classes can be extended to create subtypes. Like C++, methods are
|
|
|
|
<em>not</em> virtual by default. In Java terminology, all methods are
|
|
|
|
final by default. Multiple inheritance, like Java, is unsupported (see
|
|
|
|
<a href="#interfaces">Interfaces</a>).
|
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/class-extend.js-->
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Alternatively, if creating an anonymous subtype, the supertype's
|
|
|
|
<tt>extend()</tt> method may be used.
|
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
var SturdyCow = Cow.extend( { /*...*/ } );
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>
|
2012-05-07 00:08:59 -04:00
|
|
|
Type checks for polymorphic methods may be performed with
|
|
|
|
<tt>Class.isA()</tt>, which is <a
|
|
|
|
href="manual/Type-Checks-and-Polymorphism.html" class="man">recommended in
|
|
|
|
place of <tt>instanceof</tt></a>.
|
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/class-poly.js-->
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
To prevent a class from being extended, <a href="manual/Final-Classes.html"
|
|
|
|
class="man"><tt>FinalClass</tt></a> may be used.
|
2012-05-05 14:09:27 -04:00
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/class-final.js-->
|
|
|
|
</pre>
|
2012-05-06 23:08:21 -04:00
|
|
|
<a href="manual/Inheritance.html">→ Read more in manual</a>
|
2012-05-05 22:42:21 -04:00
|
|
|
<a href="#" class="top">↑</a>
|
2012-05-05 14:09:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
<h3 id="abstract" class="bigemph">
|
|
|
|
Abstract Classes and Methods
|
|
|
|
<span class="anchor"><a href="#abstract">¶</a></span>
|
|
|
|
</h3>
|
|
|
|
<p>
|
|
|
|
If a class contains abstract members, it must be declared as an
|
|
|
|
<tt>AbstractClass</tt>. Abstract methods must be overridden by subtypes and
|
|
|
|
are implicitly virtual.
|
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/class-abstract.js-->
|
|
|
|
</pre>
|
2012-05-06 23:08:21 -04:00
|
|
|
<a href="manual/Abstract-Members.html">→ Read more in manual</a>
|
2012-05-05 22:42:21 -04:00
|
|
|
<a href="#" class="top">↑</a>
|
2012-05-05 14:09:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
<h3 id="interfaces" class="bigemph">
|
|
|
|
Interfaces
|
|
|
|
<span class="anchor"><a href="#interfaces">¶</a></span>
|
|
|
|
</h3>
|
|
|
|
<p>
|
|
|
|
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.
|
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/interface.js -->
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
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 <a
|
|
|
|
href="#abstract"><tt>AbstractClass</tt></a>.
|
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/interface-2.js -->
|
|
|
|
</pre>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
Polymorphic methods may check whether a given object implements a certain
|
|
|
|
interface.
|
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/interface-3.js -->
|
|
|
|
</pre>
|
2012-05-06 23:08:21 -04:00
|
|
|
<a href="manual/Interfaces.html">→ Read more in manual</a>
|
2012-05-05 22:42:21 -04:00
|
|
|
<a href="#" class="top">↑</a>
|
2012-05-05 14:09:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
<h3 id="access-modifiers" class="bigemph">
|
|
|
|
Access Modifiers
|
|
|
|
<span class="anchor"><a href="#access-modifiers">¶</a></span>
|
|
|
|
</h3>
|
|
|
|
<p>
|
|
|
|
All three common access modifiers — public, protected and private
|
2012-05-06 23:43:54 -04:00
|
|
|
— are supported, but <a href="manual/Pre_002dES5-Fallback.html"
|
|
|
|
class="man">enforced only in ECMAScript 5 and later</a> environments.
|
2012-05-05 14:09:27 -04:00
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/access-modifiers.js -->
|
|
|
|
</pre>
|
|
|
|
<p>
|
|
|
|
In the above example, the database connection remains encapsulated within
|
|
|
|
<tt>DatabaseRecord</tt>. 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.
|
|
|
|
</p>
|
2012-05-06 23:08:21 -04:00
|
|
|
<a href="manual/Access-Modifiers.html">→ Read more in manual</a>
|
2012-05-05 22:42:21 -04:00
|
|
|
<a href="#" class="top">↑</a>
|
2012-05-05 14:09:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
<h3 id="static" class="bigemph">
|
|
|
|
Static and Constant Members
|
|
|
|
<span class="anchor"><a href="#static">¶</a></span>
|
|
|
|
</h3>
|
|
|
|
<p>
|
|
|
|
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
|
2012-05-06 23:43:54 -04:00
|
|
|
<a href="manual/Static-Implementation.html" class="man">pre- and
|
|
|
|
post-ECMAScript 5 environments</a>, the syntax requires use of a static
|
2012-05-05 14:09:27 -04:00
|
|
|
accessor method — <tt>$()</tt>.
|
|
|
|
</p>
|
|
|
|
<pre class="js">
|
|
|
|
<!--%inc scripts/ex/static-members.js -->
|
|
|
|
</pre>
|
2012-05-06 23:08:21 -04:00
|
|
|
<a href="manual/Static-Members.html">→ Read more in manual</a>
|
2012-05-05 22:42:21 -04:00
|
|
|
<a href="#" class="top">↑</a>
|
2012-05-05 14:09:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
<script type="text/javascript" src="scripts/highlight.pack.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// JS syntax highlighting, ES5
|
|
|
|
Array.prototype.slice.call( document.querySelectorAll( '.js' ) )
|
|
|
|
.forEach( function( element )
|
|
|
|
{
|
|
|
|
hljs.highlightBlock( element, ' ' );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
catch ( e ) {};
|
|
|
|
</script>
|