赞
踩
//longhand
if (x === 'abc' || x === 'def' || x === 'ghi' || x ==='jkl') {
//logic
}
//shorthand
if (['abc', 'def', 'ghi', 'jkl'].includes(x)) {
//logic
}
在JS中,直接使用includes方法,在其它语言中,开发者可以撰写类似的方法来简化代码,在大型项目中这种做法非常有益。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。