javascript
javascript (expr[, private])
This function sends the string expr to the JavaScript interpreter to be evaluated, returning the result as a string. By default, the JavaScript expression is evaluated in the global shared scope, so previously defined JavaScript functions are accessible. If the private parameter is specified and non-zero, the expression is evaluated in a temporary scope. As a result, top-level objects created during evaluation will be discarded on return.
The following example uses an ACL expression to create a corresponding JavaScript expression to evaluate. In this case, it calls the JavaScript Date.parse method on the current time and date as returned by the ACL time_date function, returning the number of milliseconds between the current time and date and midnight, January 1, 1970 GMT.
msecs = javascript('Date.parse("' . time_date() . '")')
The following example returns the same result as the previous example using only JavaScript. The time ACL function returns a similar result in seconds instead of milliseconds.
msecs = javascript('var d = new Date(); d.getTime()')
Related Topics