How do I expand javascript?



  • I don't know how to expand my function without changing the old code.

    function export_excel() {
        $.ajax({
            url: window.location,
            method: 'GET',
            xhrFields: {
                responseType: 'blob'
            },
            headers: {
                excelize: 'True'
            },
            success: function (data) {
                var a = document.createElement('a');
                var url = window.URL.createObjectURL(data);
                a.href = url;
                a.download = 'Отчет.xlsx';
                document.body.append(a);
                a.click();
                a.remove();
                window.URL.revokeObjectURL(url);
            }
        });
    } 
    

    I want the function export_excel(text) to accept the text, and I want a.download = text; but I need to make the old challenges of this function work correctically.



  • Default for the argument:

    function export_excel(name = 'Отчет.xlsx') {
      console.log(name);
    }
    

    export_excel(); // Выведет Отчет.xlsx
    export_excel('text'); // Выведет text


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2