我有一个这样的功能:
initGrid: function(tableGridId, url) {
var deviceTableGridId;
if (typeof tableGridId != "undefined"){
deviceTableGridId = tableGridId;
} else {
deviceTableGridId = gridId;
}
var getUrl;
if (typeof url != "undefined"){
getUrl = url;
} else {
getUrl = restUrl;
}
..
}
我该如何缩短代码的编写时间?我的意思是扩展或等?
最佳答案
var deviceTableGridId = tableGridId || gridId,
getUrl = url || restUrl;