ecmascript 6 - Khanacademy Javascript Canvas default parameter error -
i'm working on cool program on khanacademy.org javascript/processingjs canvas, , want use default parameters. however, showed error box:
'default parameters' available in es6 (use esnext option).
what , how fix it?
using default parameters in way give warning mentioned:
var foo = function(param1, param2 = "some default value"){ console.log(param1 + " " + param2); }
assigning default parameters in way described above ecmascript 6 feature , supported mozilla firefox. check browser compatibility here: https://developer.mozilla.org/en/docs/web/javascript/reference/functions/default_parameters#browser_compatibility
generally default parameters assigned in javascript in following way. suggest follow same, work fine in browsers:
var foo = function(param1, param2){ param2 = typeof param2 !== 'undefined' ? param2 : "some default value"; console.log(param1 + " " + param2); }
check link more details: https://developer.mozilla.org/en/docs/web/javascript/reference/functions/default_parameters
Comments
Post a Comment