this.duration = index == 0 ? 1000 : index == 1 ? 2000 : 3000;复杂的三元表达式你真的知道吗?

this.duration = index == 0 ? 1000 : index == 1 ? 2000 : 3000;

等同于下面的

if (index == 0) {
	this.duration = 1000;
} else {
	if (index == 1) {
		this.duration = 2000;
	} else {
		this.duration = 3000;
	}
}

以上纯属个人理解,如有不懂欢迎评论区留言哦

猜你喜欢

转载自blog.csdn.net/qq_42899245/article/details/108295056