JavaScript Tutorials - Herong's Tutorial Examples - 2.33, by Herong Yang
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 HerongYang.com. 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 cp: function cp(from, to) { if (from == to) { println("file " + from + " cannot be copied onto itself!"); return; } 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 = binp.read(buff)) > 0) { bout.write(buff, 0, len); } bout.flush(); streamClose(inp); streamClose(out); } read: 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) { java.lang.System.err.print(prompt); java.lang.System.err.flush(); var tmp = reader.readLine(); if (tmp == "" || tmp == null) { break; } line += tmp + "\n"; } return line; } else { java.lang.System.err.print(prompt); java.lang.System.err.flush(); return reader.readLine(); } } print: function print(str, newline) { if (typeof (str) == "undefined") { str = "undefined"; } else { if (str == null) { str = "null"; } } var out = context.getWriter(); out.print(String(str)); if (newline) { out.print("\n"); } out.flush(); } println: function println(str) { print(str, true); } ...
Now we know how the "println()" is implemented in "jrunscript".
Table of Contents
ECMAScript Language Specification and JavaScript Dialects
Data Types, Variables and Expressions
Creating, Accessing, and Manipulating Arrays
Defining and Calling Functions
Web Browser Supporting JavaScript
Server-Side and Client-Side Web Scripting
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