Use of ES6 Default Function Parameter Value Spec in Lightning (Aura) Components

Whilst doing some cleanup of some Aura Components for Summer 16, I was creating a JS function in my helper. I had wanted to add some default values to that function using the new ES6 Default Parameter Value Spec. Like so:

myFunction = function (param1 = "this", param2 = "that"){

Meaning that if I invoked this like

> param1 = "this"
> param2 = "that"

helper.myFunction("what is");
> param1 = "what is"
> param2 = "that"

No luck. I get an error when I attempt to save the component on the server as such:

ERROR: 0Ad240000008RPA: org.auraframework.util.json.JsonStreamReader$JsonStreamParseException: Expected ‘,’ or ‘)’ [64, 30]: ‘=’


I have just bumped in this issue and I would like to share my findings.

The following syntax is still not supported (you’ll get a JsonStreamParseException):

myFunction = function (param1 = "this", param2 = "that")

However, if you write it this way (without spaces around the equal signs), the default parameter values work fine:

myFunction = function (param1="this", param2="that")

I hope this will help someone.

Source : Link , Question Author : pchittum , Answer Author : POZ

Leave a Comment