Reputation: 1389
I'm getting a syntax error expected token ')'
in only Safari. I've found some posts on the forum saying that default parameters
aren't supported in Safari.
But how can I fix this then with the code below?
function showCartMessage(message = '', img_url = '', statusClass = ''){
if(img_url == ''){
$('.cart-message .product_notification_background').css('background', 'whitesmoke');
}else{
$('.cart-message .product_notification_background').css('background', 'url("' + img_url + '") no-repeat center center');
}
}
Upvotes: 0
Views: 146
Reputation: 8605
Simply default inside the function:
function showCartMessage(message, img_url, statusClass){
message = message || '';
img_url = image_url ||'';
statusClass = statusClass || '';
if(img_url == ''){
$('.cart-message .product_notification_background').css('background', 'whitesmoke');
}else{
$('.cart-message .product_notification_background').css('background', 'url("' + img_url + '") no-repeat center center');
}
}
So this way, any parameter coming through as undefined
will be made a blank string.
Upvotes: 2