
公司里面有人常常会有这种code, 其实我也不知道怎么修正, 能否有大神给点意见?

公司里面有人常常会有这种code, 其实我也不知道怎么修正, 能否有大神给点意见?
if(data?.exitfunc?.onclear)
直接 if (data?.exitfunc?.onclear) 或者 if (data && data.exitfunc && data.exitfunc.onclear) 就好了。
原来如此 感谢回应
话说 都用ts了为啥不加类型呢,,,虚线看着不难受吗。。。
多的是 你不知道的事
data&&data.exitfunc&&data.exitfunc.onclear&&console.log(“kkkk”);
那个判断就是我写的, 学到了啊 原来如此. 马上改
请问,函数金字塔怎么优化呢?
let a = () => {
tween(this)
.to(0.1, {})
.call(() => {
for (const test of []) {
tween(test)
.to(0.1, {})
.call(() => {
console.log("除了分块拆出去还有别的办法吗");
})
.start();
}
})
.start();
};
a();
你这个东西用SchedulelOnce比较好看吧
哈哈,我只是写了一个栗子~
最好是这样
init(data = { exitfunc: { onclear: false } }){
if(data .exitfunc.onclear){
....
}
}
性能没有提升这种改动只是为了看起来简洁一点意义不是太大自己爽爽罢了,if else 或许下个接手的人反而更容易看的懂写的是什么
这不是if波动拳么 
我想再问一个
if (game.gamelist[“one”]) {
game.gamelist[“one”].gameType = 1;
}
if (game.gamelist[“two”]) {
game.gamelist[“two”].gameType = 1;
}
if (game.gamelist[“three”]) {
game.gamelist[“three”].gameType = 1;
}
if (game.gamelist[“four”]) {
game.gamelist[“four”].gameType = 0;
}

這個有辦法優化嗎?5
改成填表格
差不多这样
var list = { "one": 1, "tow": 1, "three": 1, "four": 0 }
var ary = Object.keys(list)
ary.forEach(k => {
game.gamelist[k]?.gameType && (game.gamelist[k].gameType = list[k])
})
这边建议直接优化一下写这个代码的程序员呢。 
这边建议直接优化一下写这个代码的程序员呢。 
我每天看到都摩拳擦掌