JS的:1. p == "relative" || p == "absolute" || (this._container.style.position = "relative");2. index < 0 && (index = this._count - 1) || index >= this._count && (index = 0);3. index == undefined && (index = this.Index);这句的效果是不是判断index是undefined的时候使用this.Index?还是Bool?求高手解答
&& 后面要求是布尔值,js中0 null undefined可自动转为布尔值false,其他值比如非0数字,非空字符串,对象等自动转成true,所以 可以 && index
a||b在a为true时(因为此时a||b一定为true)不会判断b,也不会执行b,只有在a为false时b才有效。
a&&b在a为false时(因为此时a&&b一定为false)不会判断b,也不会执行b,只有在a为true时b才有效。
所以:
1、只有p既不为"relative"也不为"absolute"时才会执行最后一句;
2、可以具体化到一个数组,下标(index)小于0时设为数组最后一个元素的下标,下标大于数组最后一个元素的下标时则设为0;
3、就是你所说的“判断index是undefined的时候使用this.Index”。
if(!(p == "relative" || p == "absolute"))//前面两个只要有一个true 最后这个就不会执行
this._container.style.position = "relative";
2.
if(index<0){
index = this._count - 1;
}else if(index >= this._count ){
index = 0;
}
3.
不管是不是undefined 后面都会执行