所以我有一段代码,我有一个数组(ar = [1,2,3,4,5])和两个函数。这些函数应该完全相同:如果数组中存在1,则打印出一些东西。但是函数func总是返回" nope"而不是"一个"但功能另一个总是返回正确的东西。两个函数之间的唯一区别是函数func有一个开关而不是if / else。为什么?在源代码中有大约12个案例,所以我实际上需要使用开关。
var ar=[1,2,3,4,5];
function func(num){
var one=num;
switch (one) {
case one===1:
console.log("one");
break;
default:
console.log("nope");
break;
}
}
function another (num) {
if(num===2){
console.log("found two");
} else if(num===3){
console.log("found thre");
} else{
console.log("nope");
}
}
ar.forEach(func);
ar.forEach(another);
答案 0 :(得分:3)
答案 1 :(得分:0)
最简单的方法。如果要在大小写中使用比较,请将开关参数更改为public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
...
final float eyeX = 0.0f;
final float eyeY = 0.0f;
final float eyeZ = 7.0f;
final float lookX = 0.0f;
final float lookY = 0.0f;
final float lookZ = 0.0f;
final float upX = 0.0f;
final float upY = 1.0f;
final float upZ = 0.0f;
Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
...
}
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
...
final float ratio = width / height;
final float left = -ratio;
final float right = ratio;
final float bottom = -1.0f;
final float top = 1.0f;
final float near = 1.0f;
final float far = 20.0f;
Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
...
}
public void onDrawFrame(GL10 glUnused) {
...
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
...
}
,因为true
返回true / false。这就是为什么你总是得到" nope"。
one===1