JS.New
------

Creates a new JavaScript engine instance.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [JavaScript](component_JavaScript.md) | [10.0](newinversion100.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

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

**MBS**( **"JS.New";** /\* Creates a new JavaScript engine instance. \*/  
**$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 **11.3**. |

### Result

Returns JS reference number or error.

### Description

Creates a new JavaScript engine instance.  
This object contains all the functions and properties you defined.  
Please release the object later with the [JS.Release](JSRelease.md) function.  
  
Your own JavaScript engine is useful for:  
- Running some snippet of JavaScript code without web viewer.
- Using various JavaScript libraries
- Providing a scripting language to your own solution.
- Doing JavaScript on server side.
- Working with JSON data
- Enjoy using regular expressions, unicode text functions, number parsing and formatting with no platform dependencies

If JSRef is "js", we use this one as the global JavaScript engine for custom functions and JS.[CF](CF.md) function. See our example JavaScript Custom Functions.  
  
When using a name for the reference number, you can use this reference anywhere you need to pass a JavaScript reference number.  
  
Check also our [JavaScriptWebKit](component_JavaScriptWebKit.md) functions for using WebKit’s JavaScript engine on macOS and iOS.  
### Examples

Evaluate a bit of JavaScript:

 Set Variable \[ $js ; Value: MBS ( "JS.New" ) \]   
Set Variable \[ $r ; Value: MBS ( "[JS.Evaluate](JSEvaluate.md)"; $js ; "4+5") \]   
Show Custom Dialog \[ "Result" ; $r \]   
Set Variable \[ $r ; Value: MBS ( "[JS.Release](JSRelease.md)"; $JS ) \]  
Create named JavaScript Environment:

 Set Variable \[$js ; MBS ( "JS.New"; "js" ) \]  
### See also

- [JS.AddFileMakerSQLFunction](JSAddFileMakerSQLFunction.md)
- [JS.AddFunction](JSAddFunction.md)
- [JS.CallFunction](JSCallFunction.md)
- [JS.CF](JSCF.md)
- [JS.GetGlobalProperty](JSGetGlobalProperty.md)
- [JS.InitModules](JSInitModules.md)
- [JS.Now](JSNow.md)
- [JS.ObjectCount](JSObjectCount.md)
- [JS.TimeToUTCDate](JSTimeToUTCDate.md)
- [JS.UTCDateToTime](JSUTCDateToTime.md)

### Release notes

- **Version 11.3**
    - Added parameter for [JS.New](https://www.mbsplugins.eu/JSNew.shtml) function to define the identifier used for the new instance.

### Example Databases

- [JavaScript/CoordinatDistance](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/CoordinatDistance.shtml#1ScriptAnchor_)
- [JavaScript/FM JSON Path](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/FM%20JSON%20Path.shtml#1ScriptAnchor_)
- [JavaScript/JavaScript Custom Functions](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/JavaScript%20Custom%20Functions.shtml#2ScriptAnchor_)
- [JavaScript/JavaScript libPhoneNumber](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/JavaScript%20libPhoneNumber.shtml#10ScriptAnchor_)
- [JavaScript/JavaScript SunCalc](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/JavaScript%20SunCalc.shtml#10ScriptAnchor_)
- [JavaScript/JavaScript](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/JavaScript.shtml#1ScriptAnchor_)
- [JavaScript/RichTextToJSON](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/RichTextToJSON.shtml#15CustomFunctionAnchor_)
- [List/Sort Benchmark](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/List/Sort%20Benchmark.shtml#5ScriptAnchor_)

### Blog Entries

- [New in MBS FileMaker Plugin 11.3](https://www.mbsplugins.de/archive/2021-07-27/New_in_MBS_FileMaker_Plugin_11/monkeybreadsoftware_blog_filemaker)
- [Neues MBS FileMaker Plugin 11.3](https://www.mbsplugins.de/archive/2021-07-12/Neues_MBS_FileMaker_Plugin_113/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 11.3 - More than 6500 Functions In One Plugin](https://www.mbsplugins.de/archive/2021-07-12/MBS_FileMaker_Plugin_113_-_Mor/monkeybreadsoftware_blog_filemaker)
- [Custom Functions in JavaScript](https://www.mbsplugins.de/archive/2021-06-14/Custom_Functions_in_JavaScript/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 11.3pr2](https://www.mbsplugins.de/archive/2021-06-09/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [New in the MBS FileMaker Plugin 10.1](https://www.mbsplugins.de/archive/2020-03-17/New_in_the_MBS_FileMaker_Plugi/monkeybreadsoftware_blog_filemaker)
- [FileMaker and JavaScript - the perfect combination](https://www.mbsplugins.de/archive/2020-02-03/FileMaker_and_JavaScript_-_the/monkeybreadsoftware_blog_filemaker)
- [New in the MBS FileMaker Plugin 10.0](https://www.mbsplugins.de/archive/2020-01-23/New_in_the_MBS_FileMaker_Plugi/monkeybreadsoftware_blog_filemaker)
- [CRC function in FileMaker using JavaScript](https://www.mbsplugins.de/archive/2020-01-15/CRC_function_in_FileMaker_usin/monkeybreadsoftware_blog_filemaker)
- [Our JavaScript engine for FileMaker](https://www.mbsplugins.de/archive/2019-12-09/Our_JavaScript_engine_for_File/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 4/2021, Seite 23](https://filemaker-magazin.de/neuigkeit/4152-Appetithappen-FMM_202104)
- [Ausgabe 4/2021, Seite 20](https://filemaker-magazin.de/neuigkeit/4152-Appetithappen-FMM_202104)

This function checks for a license.

Created 7th December 2019 , last changed 4th July 2024

  
[JS.List](JSList.md) - [JS.Now](JSNow.md)

[HTML Version](JSNew.shtml)