1
0
Fork 0

Prototype wrapping using index function

This redefines the index as a function (rather than a vanilla object) so
that it may be invoked to yield an ease.js Class that wraps the given
prototype.
master
Mike Gerwitz 2015-09-09 23:25:37 -04:00
parent 1fe8a0e8d6
commit a931796bdf
2 changed files with 42 additions and 3 deletions

View File

@ -1,7 +1,7 @@
/**
* Provides ease of access to all submodules
*
* Copyright (C) 2010, 2011, 2013, 2014 Free Software Foundation, Inc.
* Copyright (C) 2010, 2011, 2013, 2014, 2015 Free Software Foundation, Inc.
*
* This file is part of GNU ease.js.
*
@ -19,10 +19,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Wrap a prototype using ease.js
*
* This function is the entry point for ease.js; its fields expose all of
* its core features. When invoked, it wraps the given prototype using
* ease.js, producing an ease.js Class. This is more natural when using the
* ECMAScript 6 `class` syntax to define prototypes.
*
* @param {Function} proto prototype to wrap
*
* @return {Function} ease.js Class wrapping PROTO
*/
var exports = module.exports = function( proto )
{
return exports.Class.extend( proto, {} );
};
exports.Class = require( './lib/class' );
exports.AbstractClass = require( './lib/class_abstract' );
exports.FinalClass = require( './lib/class_final' );
exports.Interface = require( './lib/interface' );
exports.Trait = require( './lib/Trait' );
exports.version = require( './lib/version' );

View File

@ -1,7 +1,7 @@
/**
* Tests index.js
*
* Copyright (C) 2014 Free Software Foundation, Inc.
* Copyright (C) 2014, 2015 Free Software Foundation, Inc.
*
* This file is part of GNU ease.js.
*
@ -63,4 +63,27 @@ require( 'common' ).testCase(
{
this.exportedAs( 'version', 'version' );
},
/**
* Since ECMAScript 6 introduces the ability to define prototypes using
* the `class` keyword and some syntatic sugar, it is awkward to use the
* traditional ease.js class abstraction with it. Instead, if a user
* wishes to wrap a prototype defined in this manner (to take advantage
* of ease.js' features), it would be more appropriate to make it look
* like we're doing just that.
*
* This is a shorthand for Class.extend( proto, {} ).
*/
'Invoking is equivalent to extending with empty definition': function()
{
var proto = function() {},
result = this.Sut( proto );
this.assertOk( this.Sut.Class.isClass( result ) );
// this is not a comprehensive test (once we add reflection of some
// sort, verify that nothing is added to the prototype)
this.assertOk( this.Sut.Class.isA( proto, result() ) );
},
} );