<!--
{
  "availability" : [
    "iOS: 8.0.0 - 26.0.0",
    "iPadOS: 8.0.0 - 26.0.0",
    "macCatalyst: 13.1.0 - 26.0.0",
    "macOS: 10.8.0 - 26.0.0",
    "tvOS: 9.0.0 - 26.0.0",
    "visionOS: 1.0.0 - 26.0.0",
    "watchOS: 3.0.0 - 26.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SceneKit",
  "identifier" : "/documentation/SceneKit/SCNAction/javaScriptAction(withScript:duration:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "SceneKit"
    ],
    "preciseIdentifier" : "c:objc(cs)SCNAction(cm)javaScriptActionWithScript:duration:"
  },
  "title" : "javaScriptAction(withScript:duration:)"
}
-->

# javaScriptAction(withScript:duration:)

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

```
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

A new action object.

## 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`](/documentation/SceneKit/SCNNode) object running the action as a variable named `node`.

This action is not reversible; the reverse action executes the same script.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)