Default parameters in functions

Viewing 3 reply threads
  • Author
    Posts
    • #1228607
      Ward Baxter
      Member

      Does ExtendScript not support default parameters in functions? i.e.:

      function doSomething (a, b = null, c = 100) { // do scripty things }

      I can’t get defaults to work that way, and the “old” workaround I used to use inside the function doesn’t seem to work either:

      function doSomething (a, b, c) {
      b = typeof b !== ‘undefined’ ? b : null;
      c = typeof c !== ‘undefined’ ? c : 100;
      // do scripty things
      }

      Thanks in advance.

    • #14323085
      Kal Starkis
      Member

      I believe ExtendScript is based on ye olde ES3, while default parameters are a feature of ES6, so you’re out of luck I’m afraid.

      As for your workaround, that should work in JavaScript, but ExtendScript can be a strange and unpredictable beast at times. In your sample code there, I notice you have ‘smart’ quotes around ‘undefined’, but I’m guessing that’s not in your actual code? You could try testing your variables directly against undefined instead:

      function doSomething (a, b, c) {
      b = (b !== undefined) ? b : null;
      c = (c !== undefined) ? c : 100;
      // do scripty things
      }
    • #12243944
      druparker
      Member

      I can’t get defaults to work that way, and the “old” workaround I used to use inside the function doesn’t seem to work either:

    • #12243947
      druparker
      Member

      I can’t get defaults to work that way https://tutuapp.uno/ https://9apps.ooo/ https://showbox.kim/ , and the “old” workaround I used to use inside the function doesn’t seem to work either:

Viewing 3 reply threads
  • You must be logged in to reply to this topic.
>