PhpStorm - JavaScript function parameter IDE error
Asked Answered
C

2

10

I am trying to build a reusable JavaScript function that makes use of default parameters. However, the IDE warns me I do something wrong.

enter image description here

The code is this:

function standardAjaxRequest(process_script_path, redirect = false) {

    var loading = $(".loading");
    var response_message = $(".response_message");

    // runs the ajax to add the entry submitted
    form.on("submit", function(event) {
        event.preventDefault();

        removeNoticeError();

        var data = form.serialize();

        $.ajax({
            url:      process_script_path,
            type:     "POST",
            dataType: "json",
            data:     data,
            cache:    false,
            success: function(response) {
                if(response.status === false)
                {
                    response_message.addClass("error").text(response.message).fadeIn(1);
                }
                else
                {
                    response_message.addClass("notice").text(response.message).fadeIn(1);
                    if(redirect)
                    {
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                    }
                    else
                    {
                        response_content.after(response.content);
                    }

                }
            },
            error: function() {
                response_message.addClass("error").text("There was a problem adding your entry.").fadeIn(1);
            },
            beforeSend: function() {
                toggleLoading();
            },
            complete: function() {
                toggleLoading();
            }
        });
    });
}

I really don't know what is wrong with it? Can you, please, help me understand what's going on?

Camorra answered 1/6, 2016 at 14:21 Comment(4)
Are you using ES6?Borak
#895360Borak
I am not sure which one. It's the latest IDE version so, I assume ES6?Camorra
ES6 is the version of Javascript that adds this feature, not the IDE.Debauched
L
11

You can switch the version here:

1. Press CTRL+ALT+S

2 Search for JavaScript & click the select field. and then select ECMAScript 6

View image.

Lophophore answered 1/6, 2016 at 14:39 Comment(1)
What does this have to do with the getting the IDE to stop marking the code as an error?Debauched
D
4

In Preferences->Languages & Frameworks->JavaScript, select "ECMAScript 6" from the language version menu to be able to use the new syntax features of ES6.

Debauched answered 1/6, 2016 at 14:58 Comment(1)
Useful clarifications, @Barbar. Thanks!Camorra

© 2022 - 2024 — McMap. All rights reserved.