Quantcast
Channel: Redino blog
Viewing all articles
Browse latest Browse all 80

Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

$
0
0

I try to add an Export button in ExtJS, it should do URL encoding for the search parameters and pass the generated query string to the export URL.

{
    xtype: 'button',
    text: 'Export',
    handler: function(){
        var searchParams = {
            pasm: Ext.getCmp('payment_log_pasm').getValue(),
            startDate: Ext.getCmp('payment_log_start_date').getValue(),
            endDate: Ext.getCmp('payment_log_end_date').getValue()
        };
        let qs = Ext.urlEncode(searchParams);
        console.log(qs);
        location.href = appBaseUri + '/sys/payment/export?'+qs;
    }
}

When testing above code in Chrome, following error happened:

Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode


The reason is let keyword is not allowed in non-strict mode for this version of Chrome.

One solution is to change let to var. (But it isn’t good)
The better solution is to add “use strict” statement.

So the final code should be

{
    xtype: 'button',
    text: 'Export',
    handler: function(){
        "use strict";
        var searchParams = {
            pasm: Ext.getCmp('payment_log_pasm').getValue(),
            startDate: Ext.getCmp('payment_log_start_date').getValue(),
            endDate: Ext.getCmp('payment_log_end_date').getValue()
        };
        let qs = Ext.urlEncode(searchParams);
        console.log(qs);
        location.href = appBaseUri + '/sys/payment/export?'+qs;
    }
}

The post Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode appeared first on Redino blog.


Viewing all articles
Browse latest Browse all 80

Trending Articles