.js file extension. Use the
<script> tag to
main.TV XML file (or into an
init.js file which is included in
file, then the
<script> tag including the first file
must come before the
<script> tag including the second file. The
src attribute of the
<script> tag should point to the
(typically stored in the
/* and end with
/* This is a multi-line
string, and supports special values for
undefined. Other data types, such as Dates and Regular Expressions are variations on the object type.
boolean data type has two values:
number data type is 64-bit floating point. There is no integer type. Division between two integers may produce a fractional result.
The number data type also includes the special values
(not a number) and
string data type is a sequence of zero or more Unicode characters. There is no separate character type. A character is represented
as a string of length 1. Literal strings are
quoted using the single quote (
') or double quote (
") characters. The quote characters can be used interchangeably, but must match.
'This is a string.'
"Isn't this a string? Yes!"
'A' // The character A
"" // The empty string
Escapement in strings is accomplished with the backslash (
\) character. Strings are not modifyable after creation. Strings have a
length property which is used to
determine the number of characters in the string.
var s = "Hello World!";
// In this example s.length == 12
The main difference between objects and arrays is that arrays support the
Arrays are not typed. You can mix strings, numbers, and objects in the same array.
names are case sensitive
and variable names must begin with a letter or the underscore character (
_). By convention, variable names and function names that begin with the underscore character (
intended to be private and not for public use.
Every variable that is not defined with the
var keyword in a function context becomes a global variable, also known as an implied global. Implied globals should be avoided
"" (the empty string), and the number
false. All other values are treated as
functions. When a function is a member of an object, it is called a method. There
is a special variable, called
this that is set to the object when a method of the object is called. For example, if an object
playButton has a method
this variable is set to the object
playButton. The function
toggle() can then refer
this to access the
playButton object’s data members. In a simple function call, the variable
this is set to the Global Object (or window).
functions with optional arguments. Inside the function block, a function has access to an
arguments array which contains all of the parameters that
were actually sent by the caller. Excess parameters are ignored. Missing parameters are given the value
Functions which are used to initialize objects are called constructors. By convention, the name of a constructor has an initial
capital letter. Inside the constructor the
this variable is the new object. The body of the constructor
function initializes the object’s members. The constructor returns the new object. A constructor is called with the
new prefix, for example:
var myObject = new ConstructorFunction(param1, param2, param3…);
The following is an example of an employee object defined using object literal notation:
The empty object can be created with an
Object constructor or by using two empty curly braces in object literal notation, for example:
helloWorld() written three different ways: as a constructor, as an object, and finally in object literal notation.
First, consider a simple constructor
helloWorld() that produces a single stateless object:
A second option is to simply make an empty object and augment it by assigning the methods to it, as follows:
Finally, in this third example, the same functionality can be accomplished by using object literal notation, as follows:
Object literals are a convenient notation for creating new objects. In object literal notation, a property’s value can be obtained from any expression, including another object literal. Objects can be nested as shown in the following example:
;) at the end of every simple statement. When a function is assigned to a value it should end with a semicolon (
;) just like all assignment statements.
!=operators do type coercsion. It is better to use the
!==operators, especially when comparing