Global Properties and Functions Provided by "jrunscript"

This section provides a quick description of all extra global properties and functions provided by the 'jrunscript' host environment.

In addition to global properties and functions defined in the ECMAScript specification, each JavaScript implementation may add its own global properties and functions into the invisible "Global" object.

Here is a tutorial example script that lists all global properties and functions provided by the JavaScript implementation:

// Global_Object_Properties_jrunscript.js
// Copyright (c) 2013 All Rights Reserved.

   println("\nList of global properties:");
   for (item in this) {
      println("   "+item+": "+this[item]);

If you run this script with "jrunscript", you will get a list of 59 properties and functions. Statement bodies of global functions are also listed in the output. Here are some examples:

List of global properties:

   javax.script.filename: Global_Object_Properties_jrunscript.js
   months: Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec

function cp(from, to) {
    if (from == to) {
        println("file " + from + " cannot be copied onto itself!");
    var inp = inStream(from);
    var out = outStream(to);
    var binp = new BufferedInputStream(inp);
    var bout = new BufferedOutputStream(out);
    var buff = javaByteArray(1024);
    var len;
    while ((len = > 0) {
        bout.write(buff, 0, len);

function read(prompt, multiline) {
    if (!prompt) {
        prompt = ">";
    var inp = java.lang.System["in"];
    var reader = new BufferedReader(new InputStreamReader(inp));
    if (multiline) {
        var line = "";
        while (true) {
            var tmp = reader.readLine();
            if (tmp == "" || tmp == null) {
            line += tmp + "\n";
        return line;
    } else {
        return reader.readLine();

function print(str, newline) {
    if (typeof (str) == "undefined") {
        str = "undefined";
    } else {
        if (str == null) {
            str = "null";
    var out = context.getWriter();
    if (newline) {

function println(str) {
    print(str, true);


Now we know how the "println()" is implemented in "jrunscript".

Table of Contents

 About This Book

 Introduction to JavaScript

 ECMAScript Language Specification and JavaScript Dialects

 Data Types, Variables and Expressions

 Flow Control Statements

 Creating, Accessing, and Manipulating Arrays

 Defining and Calling Functions

 Web Browser Supporting JavaScript

 Server-Side and Client-Side Web Scripting

 Introduction to Objects

 Defining Your Own Object Types

 Inheritance of Properties and Methods through the Prototype Object Chain

 'jrunscript' - JavaScript Shell Command from JDK

 Using Functions as "Function" Objects

Introduction to Built-in Object Types

 Overview of Built-in Object Types

 The "Object" Object Type - The Root Object Type

 The "Global" Object Type - The Invisible Global Container

 Global Properties and Functions Defined in ECMAScript

Global Properties and Functions Provided by "jrunscript"

 The "Function" Object Type - Functions Are Objects

 The "Array" Object Type - Arrays Are Objects

 The "JSON" Object Type - parse() and stringify()

 The "String" Object Type - Not Equal to String Primitive Type

 The "Boolean" Object Type - Wrapping Boolean Values into Objects

 The "Number" Object Type - Not Equal to Number Primitive Type

 The "Date" Object Type - Managing Dates and Times

 The "RegExp" Object Type - Regular Expression Patterns

 The "Error" Object Type - Runtime Exceptions

 The "Math" Object Type - The Math Container

 W3C's Document Object Model (DOM) Specifications

 AJAX (Asynchronous JavaScript And XML)


 Full Version in PDF/EPUB