1. Built-in support for generators
Comes in handy for generating multiple items. In particular it is commonly used for generating multiple nodes for use in layouts. Each generated node may be customized differently to accommodate different data being supplied for display.
2. Can run actions at a later time
Useful for displaying splash screens properly when there is some background processing going on. Below is some sample code that demonstrates this (in a script):
// Splash screen is displayed here.
public function run(args: String[]): Void
{
FX.deferAction(doBackgroundProcessing());
}
function doBackgroundProcessing(): Void
{
// Background processing is done here.
// Display the main screen, and then close the splash screen.
displayMainScreen();
}
What is important to remember here is that the function you are passing to the deferAction function must have a return type of Void. The deferAction function allows the splash screen to be fully displayed, and we can have the main screen displayed just after the splash screen is closed.
3. Can format dates in strings
Some concise syntax is provided by JavaFX Script to enable you to embed date formatting in strings. All of the date formatting options in the SimpleDateFormat class can be used, for example:
var formattedDate = "{%MM/dd/yy java.util.Date{}}";
In the above code a % char is used followed by the date format and a Date object to format a date in an expression. It may be possible in future JavaFX releases that regular expressions can be used as a string formatting option.
4. No support for static functions, variables and constants
An exception to this is with scripts, not classes. It would be interesting to know why JavaFX Script has no static support (an important design decision that was made?). Someone from the JavaFX development team would be able to shed more light on this.
5. Basic support for lookups (on nodes only)
Very handy when you do not want to keep a variable around, and want to temporarily access a node in order to run an action on it or make some changes. It may be possible that lookup support will be expanded to other areas (more general support) in future JavaFX releases.
6. Function parameters are immutable
At first this will be strange for those that have not done functional programming before. Since JavaFX Script has built in support for functional programming this makes sense. By making function parameters immutable it means that a function can safely perform operations on the parameter, without changing it thus when the program runs no funny side effects will occur.
7. Built-in support for mixins
Mixins are like interfaces except that you can define behavior in functions. Since mixins replace multiple inheritance it has made it easy to have a mixin or class inherit from multiple sources (mixins) in a predicable (clean) way. Do note that a mixin cannot be initialised.
8. First class internationalization support
This is one of the best features of JavaFX Script since it makes it a piece of cake to internationalize a program. Some unique syntax is used to make it easy to internationalize strings which hook up to a fxproperties file, for example:
Stage
{
title: ##"Window Title"
scene: Scene{}
}
The title property's value is tied to a key called "Window Title" which is prefixed by ## (indicates an internationalised string). Here is the corresponding resources_en.fxproperties file that contains that key:
"Window Title" = "Main Window"
Some people would consider this to be another form of lookup in JavaFX Script. It is very much up to debate if this is the case.
9. Built-in support for animation
It is much easier to handle animation when it can be done directly without the need for a library (less abstraction), and most properties can be manipulated via binding for use on a timeline. The unique JavaFX Script syntax provides a concise way to animate nodes quickly in a scene graph.
10. Built-in support for binding
Makes it very easy to keep properties in sync, thanks in part to the unique JavaFX Script syntax. Even better is the fact that you do not need to create any tedious, and error prone boiler code to do it which helps to reduce overall maintenance.
Some of the formatting of this blog post is incorrect since I am unable to get the editor to properly change the formatting (major bug). Hopefully this will be resolved in time for my next blog post.