cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

MathCAD Prime 10 - Advanced Controls - ES6 JavaScript Methods

TK421
3-Visitor

MathCAD Prime 10 - Advanced Controls - ES6 JavaScript Methods

I just got a hold of MCP10 and started playing around with the new Advanced Controls.

 

It appears that these controls are using Microsoft's Jscript version 5.8.  This is semi-equivalent to JavaScript/ES3 which is 11 versions behind the current version.  There are a lot of missing features that are commonly used in modern JavaScript, and I would like to at least upgrade to ES6.

 

I was able to add the methods for working with JSON using this code in the TextBoxEvent_Start function to download and execute the json3 polyfill...

 

 

 

var xhr = new ActiveXObject("Msxml2.XMLHTTP");
xhr.onreadystatechange = function(){ if(xhr.readystate == 4){ eval(xhr.responseText) } }
xhr.open("GET", "https://cdnjs.cloudflare.com/ajax/libs/json3/3.3.2/json3.min.js");
xhr.send();

 

 

 

Tangent: Yes, I know eval() is evil, and this opens me up to security risks if cloudflare ever starts sending me something malicious instead of the json3 polyfill.  If anyone has a safer solution I am happy to hear it.

 

...but I haven't been able to get a shim working so I can use other missing methods such as string.includes(), array.find(), etc., etc.  I even tried shimming ES5 before I shimmed ES6 but no go... I get the "Object doesn't support this property or method" error at line 18 where I try to use Outputs[0].Value = myString.includes("world");

 

 

 

function TextBoxEvent_Start(Inputs, Outputs) {
    var xhr = new ActiveXObject("Msxml2.XMLHTTP");
    xhr.onreadystatechange = function(){ if(xhr.readystate == 4){ eval(xhr.responseText) } }
    xhr.open("GET", "https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.14/es5-shim.min.js");
    xhr.send();
    xhr.open("GET", "https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.5/es6-shim.min.js");
    xhr.send();
};

function TextBoxEvent_Exec(Inputs, Outputs) {
    var myString = "Hello world, welcome to the universe.";
    Outputs[0].Value = myString.includes("world");
};

function TextBoxEvent_Stop(Inputs, Outputs) {
};

 

 

 

Anyone have any ideas on how I could get ES6 methods working? 

 

Update: ES5 methods work (tried string.trim), just not ES6 methods.

0 REPLIES 0
Top Tags