ECMAScript data types

From EduTech Wiki
Jump to: navigation, search

This article or section is a stub. A stub is an entry that did not yet receive substantial attention from editors, and as such does not yet contain enough information to be considered a real article. In other words, it is a short or insufficient piece of information and requires additions.

Draft


For now, this is a simple outline to keep track of the concepts that are assumed to have been described.

1 Introduction

For now we describe the data types you need to write basic programs.

2 Primitive Data Types

Boolean, int, Null, Number, String, uint, and void.

2.1 Numbers

Number. Data type representing any sort of number. int. Integer. Data type representing a number with no decimal part. uint. Unsigned integer. Data type representing a non negative integer

2.2 Strings

A variable of string data types represent a sequence of characters.

2.3 Boolean

Variables defined as of boolean type can hold only two values: true or false. No other values are valid. When a boolean variable is declared without being given an initial value, its value is false.

2.4 Null

The Null data type contains only one value, null

2.5 void

The void data type contains only one value, undefined.

3 Complex data types in ActionScript core classes

The full list of ActionScript 3 datatypes include: Object, Array, Date, Error, Function, RegExp, XML, and XMLList.

3.1 Arrays

To create an array and to add some values, you can use something like:

var mylist = Array ();
mylist[]=1;
mylist[]=2; mylist[]=3;

or

var mylist = [1,2,3];

Default numbering of elements starts at zero.

mylist[0]; // will return 1, i.e. the first element.

You can define the length of an array:

var mylist = new Array(12);

But it then can be increased later, e.g. this is ok:

mylist(14) = "bla";

There are several sorts of arrays:

  • normal arrays (as seen above)
var xx = [1,2,3];

But then we also can have:

  • typed arrays (ECMAScript 4 / JavaScript 2 - not tested !)
var xx = [ int] (12); // an array of 13 integer elements
var xx = [1,2,3] : [int]; // an array filled with 2 int. elements
var xx = new [int] (1,2,3); // same
  • associative arrays (records)
var hash = { x:10, y:"foo" }
This will return 10:
alert(hash ['x']);
  • typed associative arrays (ECMAScript 4 / JavaScript 2 - not tested !)
var hash = new { x:int, y:string }( 3, "foo" )
var hash = { x:10, y:"foo" } : { x:int, y:string }

3.2 Objects

Objects are an unordered collection of properties each of which contains a primitive value, object, or function. A function stored in a property of an object is called a method.

Internally speaking, objects are a kind of associative arrays or whatever they are called (e.g. records or hash structures). In fact, arrays are a special case of objects, i.e. an array is defined by the global JS object Array.prototype

Anyhow, the following should be internally the same or mostly (?) the same.

var take1 = {'prop1':0, 'prop2':1, 'prop2':2};

var take2 = new Object();
take2['prop1'] = 0;
take2['prop2'] = 1;
take2['prop3'] = 2;

var take3 = new Object();
take3.prop1 = 0;
take3.prop2 = 1;
take3.prop3 = 2;

4 Links

4.1 Manuals and specifications

Flash 9/ActionScript 3
JavaScript 1.5
ECMAScript

4.2 JavaScript Tutorials