user526206 user526206 - 2 months ago 9x
Android Question

Uncaught SyntaxError in javascript function

I am trying to use the below function in my code which is running in cordova android application but getting syntax error: "Uncaught SyntaxError: missing ) after argument list" which pointing at:

[src, gainNode, dst].reduce((a, b) => a && a.connect(b));

Here is a function:

function modifyGain (stream, gainValue){

var audioTrack = stream.getAudioTracks()[0];
var ctx = new AudioContext();
var src = ctx.createMediaStreamSource(new MediaStream([audioTrack]));
var dst = ctx.createMediaStreamDestination();
var gainNode = ctx.createGain();
gainNode.gain.value = gainValue;
[src, gainNode, dst].reduce((a, b) => a && a.connect(b)); // syntax error on this line


Here is my browser info:

5.0 (Linux; Android 4.4.4; D5503 Build/14.4.A.0.108) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Crosswalk/15.44.384.12 Mobile Safari/537.36

It is working fine on chrome 51 on my mac but give syntax error in android phone. Can someone tell me a reason and how i can simplyfy this rather than using expression.


Try writing this line of code in ES5 syntax

[src, gainNode, dst].reduce( function(a, b) { return a && a.connect(b) });