NAME

JE::Types - JavaScript types and objects

This is just documentation, not a real module.

DESCRIPTION

The various JavaScript types and objects are represented by classes in JE. Each class provides the methods listed below. In some cases, a class may throw an exception when the method is called.

If you are creating your own object classes in Perl for JavaScript to use, you can subclass JE::Object, but you don't have to. Just make sure that you provide all the methods listed below.

WHICH CLASSES ARE WHICH

Each built-in JavaScript class is a Perl class underneath. Here is the (not yet) complete list of objects:

JavaScript  Perl
----------------
Object      JE::Object
Function    JE::Object::Function
String      JE::Object::String
Array       JE::Object::Array
Boolean     JE::Object::Boolean
Number      JE::Object::Number
Date        JE::Object::Date

And here are the primitive types:

string      JE::String
number      JE::Number
boolean     JE::Boolean
null        JE::Null
undefined   JE::Undefined

METHODS

prop($name)
prop($name, $new_value)

Gets or sets a property. Setting a property returns the new value. The new value will be converted to a JS value automatically if it is not one already. (See UPGRADING VALUES, on the JE::Object man page.)

props

Returns a list of the names of enumerable properties

delete($name)

Deletes the property named $name, if it is deletable. Does nothing otherwise.

method($name, $arg1, $arg2, ...)

Invokes the specified method through the object. The arguments are automatically upgraded.

value

This returns a value that is supposed to be useful in Perl. JE::Object::Array->value, for instance, produces an array ref.

typeof

Returns a JE::String containing the type of the object. Used by the JS typeof operator.

id

This returns a unique id for the object or primitive, used by the JavaScript === operator. This id is unique as a string, but not as a number (even though all JE::Object:: classes return a number).

call($arg1, $arg2)

Runs the code associated with the object if it is a function. The arguments are automatically upgraded.

primitive

Returns true or false.

def_value

Returns the default value by calling either toString or valueOf.

prototype
prototype ( $obj )

This method returns the prototype of the object. If $obj is specified, the prototype is set to that object first. The prop method uses this method. You should not normally need to call it yourself, unless you are subclassing JE::Object.

to_primitive
to_string
to_number

These each return a JS primitive type.

VARIABLES

$JE::undef

The JavaScript undefined value.

$JE::null

The JavaScript null value.

FUNCTIONS

JE::Object::upgrade

See JE::Object.

SEE ALSO

JE and all the modules listed above.

UPGRADING VALUES, on the JE::Object man page