ECMAScript

出自OpenFace

(重定向自B.ECMAScript)
跳转到: 导航, 搜索

Prev

                                      Appendix B. ECMAScript

                                       Part XI. Appendices


Including Script

Script can go in four places in an LZX application:

Inside an event attribute such as onclick.

<canvas height="30">
  <button onclick="animate('x', 10, 1000, true)">Click</example>
</canvas>


In a <method> or <script> tag.

In an attribute with type expression.

Inside a constraint expression.

In a separate file that is included via the src attribute of the <script> tag.

<canvas>
  <include href="script.js"/>
</canvas>



Differences between ECMA-262 and LZX

The syntax and behaviour of LZX script is intended to be as specified by the ECMA-262 standard. However, there are some differences to be aware of.

Case-sensitivity Identifiers are not case sensitive. For example, Boolean and boolean refer to the same value.

The best practice is to use identifiers with the proper case, as this discrepancy from ECMA-262 will be removed in a future release.

Exceptions There are no exceptions, and no exception handling. try/catch/finally is not supported.

Errors such as 1/0, u(), k(), u.p, and o.u (where u is an undeclared variable, k is defined but isn't a function, and o is an object with property p) are silently ignored. (If debugging is enabled, all but the first of these will generate a warning message in the debugger window when evaluated.)

The best practice for detecting program errors in LZX code is to develop with debugging enabled (Chapter 45, Debugging) and to write unit tests (Chapter 46, Unit Testing).

The best practice for non-local transfer of control is to return a distinguished value or set a state variable.

String conversion When a String appears in a boolean context, only Strings that can be parsed as a non-zero number evaluate to true. The best practice is to use string.length to test for non-empty.

undefined conversion undefined converts to "" in a string context and to 0 in a numeric context. The best practice is to test for undefined explicitly using typeof(expression) == "undefined".

ECMAScript Objects Some ECMAScript objects and properties are not supported. See Table B.1, “Supported ECMAScript Properties” for a list of supported objects.

Browser Objects ECMA-262 is NOT the same as client-side JavaScript as implemented by web browsers. This means that the objects that are browser specific (e.g. window, document, etc.) are not available to the LZX developer.

Unicode Only Latin-1 and Shift-JIS characters are supported.

Forward references Forward references to functions are not supported.

LZX does not support the ECMAScript objects, attributes and methods presented in this font in the following table.

Table B.1. Supported ECMAScript Properties

ECMA Object Properties Methods Arguments callee

length


Array Array.prototype

constructor

length

Array(...)

new Array(...)

concat(...)

join(separator)

pop()

push(...)

reverse()

shift()

slice(start, end)

sort(comparefn)

splice(start, delete, ...)

toLocalString()

toString()

unshift(...)


Boolean Boolean.prototype

constructor

Boolean(value)

new Boolean(value)[a] [b]

toString()

valueOf()


Date Date.prototype

constructor

Date(...)

new Date(ms)

new Date(...)

new Date(string)[c]

parse(string)[c]

Date.UTC(...)

get[UTC]Date()

get[UTC]Day()

get[UTC]FullYear()

get[UTC]Hours()

get[UTC]Millisconds()

get[UTC]Minutes()

get[UTC]Month()

get[UTC]Seconds()

getTime()

getTimezoneOffset()

getYear()

set[UTC]Date(date)

set[UTC]FullYear(year[, month[, date]])

set[UTC]Hours(hours[, min[, sec[, ms]]])

set[UTC]Milliseconds(ms)

set[UTC]Minutes(minutes[, sec[, ms]])

set[UTC]Month(month[, date])

set[UTC]Seconds(sec[, ms])

setTime(ms)

setYear(year)

todateString()

toGMTSting()

toLocaleDateString()

toLocaleString()

toLocaleTimeString()

toString()

toTimeString()

toUTCString()

valueOf()


Error Error.prototype

constructor

message

name

Error(message)

new Error(message)

toString()


EvalError EvalError.prototype

constructor

message

name

EvalError(message)

new EvalError(message)

toString()


Function Function.prototype

constructor

length

Function(...)

new Function(...)

apply(this, args[])

call(this, ...)

toString()


Global Infinity

NaN

undefined

decodeURI()

decodeURIComponent()

encodeURI(uri)

encodeURIComponent(component)

escape(string)

eval(string)[d]

isFinite(number)

isNaN(number)

parseFloat(string)

parseInt(string[, radix])

unescape(string)


Math Math.E

Math.LN2

Math.LOG2E[e]

Math.PI

Math.SQRT1_2

Math.SQRT2

abs(x)

acos(x)

asin(x)

atan(x)

atan2(x, y)

ceil(x)

cos(x)

exp(x)

floor(x)

log(x)

max(...)[f]

min(...)[f]

pow(x, y)

random()

round(x)

sin(x)

sqrt(x)

tan(x)


Number Number.prototype

Number.MAX_VALUE

Number.MIN_VALUE

Number.NaN

Number.NEGATIVE_INFINITY

Number.POSITIVE_INFINITY

constructor

Number(value)

new Number(value)

toString()

toLocalString()

toFixed()

toExponential()

toPrecision()

valueOf()


Object Object.prototype

constructor

Object()

Object(value)[g]

new Object()

hasOwnProperty(v)

isPrototypeOf(v)

propertyIsEnumerable(v)

toLocalString()

toString()[h]

valueOf()


RangeError RangeError.prototype

constructor

message

name

RangeError(message)

new RangeError(message)

toString()


ReferenceError ReferenceError.prototype

constructor

message

name

ReferenceError(message)

new ReferenceError(message)

toString()


RegExp RegExp.prototype

constructor

global

ignoreCase

lastIndex

multiline

source

RegExp(pattern, flags)

new RegExp(pattern, flags)

exec(string)

test(string)


String String.prototype

constructor

length

String(value)

new String(value)[i]

String.fromCharCode(...)

charAt(pos)

charCodeAt(pos)

concat(...)

indexOf(searchstr[, start])

lastIndexOf(searchstr[, start])

localeCompare(that)

match(regexp)

replace(searchstr, replacement)

search(regexp)

slice(start[, end])

split(delimiter)

substring(start[, end])

toLocaleLowerCase()

toLocaleUpperCase()

toLowerCase()

toString()

toUpperCase()

valueOf()


SyntaxError SyntaxError.prototype

constructor

message

name

SyntaxError(message)

new SyntaxError(message)

toString()


TypeError TypeError.prototype

constructor

message

name

TypeError(message)

new TypeError(message)

toString()


URIError URIError.prototype

constructor

message

name

URIError(message)

new URIError(message)

toString()


[a] new Boolean() may not be used to coerce a String to a Boolean.

[b] new Boolean() may not be used to clone a wrapper.

[c] new Date(string) and Date.parse() are not supported. Passing a string to new Date(datestring) is not supported. The best practice is to construct dates from date components, for example: in place of new Date("7/20/1969") use new Date(1969, 7, 20).

[d] The eval() function cannot be used to execute arbitrary code. It may only be used only to get the value of an identifier named by a String.

[e] Math.LOG2E is incorrect on the Flash 5 player

[f] Math.max() and Math.min() only support two arguments.

[g] Using Object() to create a wrapper is not supported.

[h] Object.toString always returns "[object Object]".

[i] Using new String(value) to clone a wrapper is not supported.


Reserved Words

Reserved words may not be used as identifiers:

Table B.2. ECMAScript Keywords

Keywords Reserved for future use break for throw case function try catch if typeof continue in var default instanceof void delete new undefined do return while else switch with finally this abstract final protected boolean float public byte goto short char implements static class import super const int synchronized debugger interface throws double long transient enum native volatile export package extends private


A property of an object may have any name, even that of a reserved word. object.property and object['property'] both refer to the property property of the object named object. When using dot syntax (object.property) property names must be a valid identifiers, so object.default, for example, is a syntax error. In this case object['default'] can be used instead.


Home

Prev