---
title: "javaScriptAction(withScript:duration:)"
framework: scenekit
role: symbol
role_heading: Type Method
path: "scenekit/scnaction/javascriptaction(withscript:duration:)"
---

# javaScriptAction(withScript:duration:)

Creates an action that executes a JavaScript script periodically over a specified duration.

## Declaration

```swift
class func javaScriptAction(withScript script: String, duration seconds: TimeInterval) -> SCNAction
```

## Parameters

- `script`: A string containing JavaScript source code.
- `seconds`: The duration of the action, in seconds.

## Return Value

Return Value A new action object.

## Discussion

Discussion SceneKit exposes its classes, methods, and functions in the JavaScript context that runs the script—see the SCNJavaScript.h header file for details. When the action executes, SceneKit runs the script repeatedly until the action’s duration expires. Each time SceneKit runs the script, it computes the elapsed time since the action began executing (as a fraction of the action’s duration between 0.0 and 1.0) and makes it available to the script as a variable named elapsedTime. The script can also reference the SCNNode object running the action as a variable named node. This action is not reversible; the reverse action executes the same script.

## See Also

### Creating Custom Actions

- [run(_:)](scenekit/scnaction/run(_:).md)
- [run(_:queue:)](scenekit/scnaction/run(_:queue:).md)
- [customAction(duration:action:)](scenekit/scnaction/customaction(duration:action:).md)
