Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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?

share|improve this question
    
Are you using ES6? – Sandeep Nayak Jun 1 at 14:23
    
    
I am not sure which one. It's the latest IDE version so, I assume ES6? – F. Gran Jun 1 at 14:26
    
ES6 is the version of Javascript that adds this feature, not the IDE. – Barmar Jun 1 at 14:47
up vote 0 down vote accepted

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.

share|improve this answer
    
What does this have to do with the getting the IDE to stop marking the code as an error? – Barmar Jun 1 at 14:47
    
@Barmar My bad updated the answer, – ThomH Jun 1 at 14:56

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

share|improve this answer
    
Useful clarifications, @Barbar. Thanks! – F. Gran Jun 1 at 15:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.