JavaScript.New
--------------

Creates a new javascript context.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [JavaScriptWebKit](component_JavaScriptWebKit.md) | [5.4](newinversion54.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "JavaScript.New" { ; JSRef } ) 

**MBS**( **"JavaScript.New";** /\* Creates a new javascript context. \*/  
**$JSRef**) /\* Optional; The desired js reference.  
Usually each one gets a number assigned, but you can create a JavaScript environment with a fixed name, so you can anywhere reference it by name.e.g. "JS" \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| JSRef | The desired js reference.   Usually each one gets a number assigned, but you can create a JavaScript environment with a fixed name, so you can anywhere reference it by name. | "JS" | Optional      Added in version **12.2**. |

### Result

Returns reference number or error.

### Description

Creates a new javascript context.  
  
Reference numbers start at 47000.  
Works in FileMaker 32-bit and 64-bit.  
  
Supported for iOS with MBS Plugin 7.5.  
  
Check JS Functions for JavaScript engine cross platform.  
### Examples

Initialize:

 Set Variable \[ $r ; Value:MBS ("JavaScript.New") \]  
If \[ MBS ("IsError") \]  
 Show Custom Dialog \[ Title: "Failed to initialize"; Message: $r ; Default Button: “OK” \]  
Else  
 Set Variable \[ $$Context ; Value:$r \]  
 Show Custom Dialog \[ Message: "OK"; Default Button: “OK” \]  
End If  
### See also

- [IsError](IsError.md)
- [JavaScript.CF](JavaScriptCF.md)
- [JavaScript.CheckScriptSyntax](JavaScriptCheckScriptSyntax.md)
- [JavaScript.EvaluateScript](JavaScriptEvaluateScript.md)
- [JavaScript.GetProperty](JavaScriptGetProperty.md)
- [JavaScript.List](JavaScriptList.md)
- [JavaScript.RegisterEvaluateFunction](JavaScriptRegisterEvaluateFunction.md)
- [JavaScript.SetProperty](JavaScriptSetProperty.md)

### Release notes

- **Version 13.1**
    - Fixed [JavaScript.New](https://www.mbsplugins.eu/JavaScriptNew.shtml) to work on iOS again.
- **Version 12.2**
    - Added new parameter for [JavaScript.New](https://www.mbsplugins.eu/JavaScriptNew.shtml) to name the instance.

### Example Databases

- [JavaScript/RichTextToJSON](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/RichTextToJSON.shtml#7CustomFunctionAnchor_)
- [JavaScript WebKit/JavaScript](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript%20WebKit/JavaScript.shtml#1ScriptAnchor_)
- [JavaScript WebKit/JavaScriptMac Custom Functions](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript%20WebKit/JavaScriptMac%20Custom%20Functions.shtml#2ScriptAnchor_)

### Blog Entries

- [Using JavaScript with WebKit on FileMaker Server on Linux](https://www.mbsplugins.de/archive/2023-03-05/Using_JavaScript_with_WebKit_o/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 13.1pr1](https://www.mbsplugins.de/archive/2023-02-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 12.2](https://www.mbsplugins.de/archive/2022-06-09/MBS_FileMaker_Plugin_122/monkeybreadsoftware_blog_filemaker)
- [Custom Functions in JavaScript reloaded](https://www.mbsplugins.de/archive/2022-05-05/Custom_Functions_in_JavaScript/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.2pr5](https://www.mbsplugins.de/archive/2022-05-04/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 5th November 2015 , last changed 9th February 2023

  
[JavaScript.LoadLibrary](JavaScriptLoadLibrary.md) - [JavaScript.RegisterEvaluateFunction](JavaScriptRegisterEvaluateFunction.md)

[HTML Version](JavaScriptNew.shtml)