dev*_*evo 16 javascript console jquery google-chrome pnotify
我有一个接受可选参数的javascript函数.这很好用Firefox,但在Google Chrome其中显示: -
Uncaught SyntaxError: Unexpected token =
Run Code Online (Sandbox Code Playgroud)
我的代码,
function errorNotification(text = "Something went wrong!") {
$.pnotify({
title: 'Error',
text: text,
type: 'error'
});
}
Run Code Online (Sandbox Code Playgroud)
我见过很多类似的问题,但我无法实现我的问题.
Aru*_*hny 32
您正在使用默认参数功能,现在仅支持Firefox.
function errorNotification(text) {
text = text || "Something went wrong!";
$.pnotify({
title: 'Error',
text: text,
type: 'error'
});
}
Run Code Online (Sandbox Code Playgroud)
Javascript不允许您传递这样的默认参数.您需要在函数内部分配默认值.
function errorNotification(text) {
text || (text = "Something went wrong!");
$.pnotify({
title: 'Error',
text: text,
type: 'error'
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11875 次 |
| 最近记录: |