Summary
The document class is represented by a single object called document. This object is used to perform utility functions. These include console text input and output, file save and load, and view event dispatching. void write(text[,text,...])
void writeln(text[,text,...])
void clear()
string readln([prompt])
string load(file)
boolean save(file,text)
void wait([handler])
void sleep(delay)
Example
document.write("hello,");
document.writeln("world");
name = document.readln("Name:");
document.writeln("hello " + name);
if(name == "clear") {
document.clear();
}
res = document.save("file1", "some text content");
text = document.load("file1");
document.writeln("file content: " + text);
document.wait();
write
Write text to the output console
void write(text[,text…])
Parameters
text - string, text to write to console
Return Value
none
Notes
Multiple strings can be passed to the method and it will print them all in sequence
writeln
Write text line to the console
void writeln(text[,text…])
Parameters
text - string, text to write to console
Return Value
none
Notes
Multiple strings can be passed to the method and it will print them all in sequence. All output is followed by a new line.
clear
Clear console output
void clear()
Parameters none
Return Value
none
Notes
Clear console text output
readln
Read a line of text from the console and return it
string readln([prompt])
Parameters
prompt - string, optional prompt to show next to input line
Return Value
Text entered on the console line as string
Notes
This method will block execution until the line is entered
load
Load text from a text file
string load(file)
Parameters
file Path and name of file to open and get content
Return Value
Text content of the file as a string if the file exists. null is returned if the file doesn't exist
Notes
The file path is relative to the folder that the current JavaScript file is running from. Jasic supports loading ANSI and Unicode text files.
save
Save text to file
string save(file,text)
Parameters
file - string, file and optional path for file to write to
text - string text to write to file
Return Value
none
Notes
File is saved as a Unicode text file.
wait
Enter event processing loop and dispatch all view events to event handlers.
void wait([handler])
Parameters handler - optional function to call when the user terminates execution
Return Value
none
Notes
This is a very important method since it is responsible for processing user event input and dispatching to the appropriate event handlers in code. If the method is not called, the application will exit by default. The optional handler is invoked on exit to allow for program termination logic such as saving state. The user stops the execution of a Jasic application in one of two ways, by hitting the stop button in the user interface, or by switching away from Jasic to the home screen or any other application.
sleep
Delay execution for a number of seconds
void sleep(delay)
Parameters delay - number, number of seconds to wait (can be fraction of a second)
Return Value
none
Notes
This will halt execution on the running script for a given number of seconds. No input or event handler are processed during this delay and the app will not be stoppable during the delay.