elixir_script v0.26.0 JS

This module defines macros and functions which implement JavaScript functionality that may not translate easily to Elixir. For instance, creating a new object, or updating an existing one.

Summary

Functions

Returns a reference to the global JavaScript object

Determines if term is a generator

Macros

Defines a generator. This is compiled into a generator function in JavaScript. defgen and defgenp are currently the only ways to use process in Elixirscript right now

Defines a private generator. This is compiled into a generator function in JavaScript

Determines if value is an instance of type

Creates new JavaScript objects

Provides a convenient way to create a string-based map

Throws the term given

Returns the type of the given value

Updates an existing JavaScript object

Yields the current generator function

Yields the current generator function with the given term

Yields control to the given generator

Functions

global()

Returns a reference to the global JavaScript object.

In browsers this would be window or self. In node this would be the global object.

is_generator(term)

Determines if term is a generator

Macros

defgen(call, expr \\ nil)

Defines a generator. This is compiled into a generator function in JavaScript. defgen and defgenp are currently the only ways to use process in Elixirscript right now.

defgenp(call, expr \\ nil)

Defines a private generator. This is compiled into a generator function in JavaScript.

instanceof(value, type)

Determines if value is an instance of type.

new(module, params)

Creates new JavaScript objects.

ex: JS.new User, [“first_name”, “last_name”]

object(args)

Provides a convenient way to create a string-based map.

Elixirscript, by default turns the following, %{a: "b"} into {[Symbol.for("a")]: "b"} in JavaScript. In order to get string keys, one would have to do %{"a" => "b"} which turns into {a: "b"} in JavaScript. With Kernel.object, you can create string keyed maps conveniently, object(a: "b") which turns into {a: "b"}

throw(term)

Throws the term given

typeof(value)

Returns the type of the given value

update(object, map)

Updates an existing JavaScript object.

ex: JS.update elem, %{“width” => 100}

yield()

Yields the current generator function

yield(term)

Yields the current generator function with the given term

yield_to(gen)

Yields control to the given generator