elixir_script v0.14.0 ElixirScript.JS

Summary

Macros

Imports a JavaScript module

Creates new JavaScript objects

Turns an ElixirScript data structure into a JavaScript one

Turns an ElixirScript data structure into JSON

Updates an existing JavaScript object

Macros

import(module, from)

Imports a JavaScript module.

Elixir modules can use the normal import, alias and require, but JavaScript modules work differently and have to be imported using this.

If module is not a list, then it is treated as a default import, otherwise it is not.

ex: JS.import A, “a” #translates to “import {default as A} from ‘a’”

JS.import [A, B, C], “a” #translates to “import {A, B, C} from ‘a’”

new(module, params)

Creates new JavaScript objects.

ex: JS.new User, ["first_name", "last_name"]

to_js(value)

Turns an ElixirScript data structure into a JavaScript one.

to_json(value)

Turns an ElixirScript data structure into JSON.

update(object, property, value)

Updates an existing JavaScript object.

ex: JS.update elem, “width”, 100