Utils¶
There’s a utils
module with several utility / helper functions.
cleanContextEval¶
- cleanContextEval(code, context)¶
A function to run arbitrary JavaScript code in a clean context / scope.
This is basically an
eval()
function on steroids. Whileeval()
works and looks alright out of the box, you always have one big issue - the scope. Theeval()
function will always run in the current scope where it’s called, thus evaluating the arbitrary JavaScript code, can have side effects for the scopeeval()
is currently run in.This function will avoid those side effects, by simply running the arbitrary JavaScript
code
in a new anonymous function. Since the code might require somecontext
(vars), it will be passed to the function as well.- Arguments:
code (String) – The arbitrary JavaScript code to run
context (Object) – The context (vars) for the code
- Returns:
The return value of the evaluated code
getPath¶
- utils.getPath(path)¶
Get the path to a Translucent file or directory relative to the included translucent script path. The returned path can be used to include additional translucent resources.
- Arguments:
path (String) – A file or directory name within translucent
- Returns:
String – The path of the file or directory