js策略模式 以及 es6中 ?? 的用法

策略模式,es6中 ?? 的用法

const judge = function(status){
	const map = [
		0: '普通用户',
		1: '管理员',
		2: '超级管理员'
	]
				
	return map[status]??'未知用户'
}

?? 是ES6提供的一个操作符,被称为非空运算符,例如 a?? ' b '  ,如果a的值不为null,则取a的值,如果a的值为null,则取b

posted @ 2023-03-23 14:20  梓色心晴  Views(42)  Comments(0Edit  收藏  举报