Overview

The purpose of the Tutorial is to give an introduction on how to create programs using the JavaScript programming language by running them using Seed. Also included are sub-tutorials to some of the Gnome libraries that Seed uses.

The assumption is that whoever is using this tutorial has some basic knowledge of computer programming but does not necessary mean knowledge of JavaScript and/or the Gnome Libraries.

Style

As much as possible, I am going to put example code in the context of a program so that it can be easily be copied and pasted into any editor and run. This is different from other tutorials I have encountered that place the program code at beginning and then add fragments of code later on. I find this fragmented approach confusing and for most folk they love to jump in, play about with the code and then come back to the tutorial when they need more information.

Status

Please note that this is a work in progress and is no where near to completion. Parts of the tutorial are a wee bit rough round the edges due to being lifted from my blog. There are other parts that I have written from scratch and the priority is firstly to get something written down.

Once I finish the basics section, I will review and tidy it up.

Exploring Seed

There are two ways on how to run JavaScript code using Seed. One is to use the interactive console and the other is to interpret text files containing JavaScript code.

Using Seed Console

The first way of using the interactive console is to enter it by using the following command on the Linux console:

seed

Once the interactive console is activated, you will be greeted with the following prompt:

>

You can enter any piece of JavaScript code into the console and the code will be run.

Running .js files

The second way of interpreting files of JavaScript code is simply to use Seed following by the name of the file. An example is if you had a file containing JavaScript code called hello_world.js, you would run this on the Linux console:

seed hello_world.js

The program will run and will display any output in terminal if the program is set-up to do so.

Alternatively, if the JavaScript file has the correct file permissions and the correct environment header, it can be run with out using it as a command line argument of Seed. It would then simply be run as follows:

./hello_world.js

More on this later.

First Program

As with every tutorial, it has to start with the hello World program. Copy the following code into your favourite editor.

As mentioned, JavaScript, or JS as I will now call them, files can be run with or without Seed. To run without Seed, enter the following command in the Linux Terminal

chmod +x hello_world.js

The command chmod changes the permissions of the specified file. The mode +x sets the file to execute. This allows the files to be run without Seed which is done by entering the following command on the console:

./hello_world.js

Predictably, the output is as follows:

Hello, world!

Going back to the program, a bit simple but here is an explanation of it:

#!/usr/bin/env seed

This is referred to as a Shebang (#!) which tells the console to use the specified interpreter to compile the text file. This is done through the env program which uses the appropriate environment variable set by your distro to where Seed is installed.