为什么这两个代码块会产生不同的结果?第一个代码块似乎返回false,但第二个代码块正常工作。在第一个块中,我甚至打印了所有布尔操作的值,这些操作都是真的,但它仍然返回false。
return
mm_card_type_flag &&
mm_mm_flag &&
mm_yyyy_flag &&
$('#hdfccc .' + 'card_no').val() == user_selections.mm_hdfccc_details.mm_number &&
$('#hdfccc .' + 'cvv_no').val() == user_selections.mm_hdfccc_details.mm_cvv &&
$('#hdfccc .' + 'card_name').val() == user_selections.mm_hdfccc_details.mm_name &&
$("#hdfccc .ignorebank").prop('checked') == user_selections.mm_hdfccc_details.ignorebank &&
$("#hdfccc .password").val() == user_selections.mm_hdfccc_details.password &&
$('#hdfccc input[name="acsRadio"]:checked').val() == user_selections.mm_hdfccc_details.radio_val &&
$("#hdfcc-secure-pin").val() == user_selections.mm_hdfccc_details.mm_secure_pin &&
$("#hdfccc .prevent-toofast-c").prop('checked') == user_selections.mm_hdfccc_details.prevent_too_fast_c;
和
var ret = mm_card_type_flag &&
mm_mm_flag &&
mm_yyyy_flag &&
$('#hdfccc .' + 'card_no').val() == user_selections.mm_hdfccc_details.mm_number &&
$('#hdfccc .' + 'cvv_no').val() == user_selections.mm_hdfccc_details.mm_cvv &&
$('#hdfccc .' + 'card_name').val() == user_selections.mm_hdfccc_details.mm_name &&
$("#hdfccc .ignorebank").prop('checked') == user_selections.mm_hdfccc_details.ignorebank &&
$("#hdfccc .password").val() == user_selections.mm_hdfccc_details.password &&
$('#hdfccc input[name="acsRadio"]:checked').val() == user_selections.mm_hdfccc_details.radio_val &&
$("#hdfcc-secure-pin").val() == user_selections.mm_hdfccc_details.mm_secure_pin &&
$("#hdfccc .prevent-toofast-c").prop('checked') == user_selections.mm_hdfccc_details.prevent_too_fast_c;
return ret;
全功能
function hdfccc_options_iSame()
{
var mm_card_type_flag = true;
var mm_mm_flag = true;
var mm_yyyy_flag = true;
if (user_selections.mm_hdfccc_details.mm_card_type)
{
mm_card_type_flag = ($('#hdfccc .' + 'card_type').val() == user_selections.mm_hdfccc_details.mm_card_type);
}
if (user_selections.mm_hdfccc_details.mm_mm)
{
mm_mm_flag = ($('#hdfccc .' + 'card_expiry_mon').val() == user_selections.mm_hdfccc_details.mm_mm);
}
if (user_selections.mm_hdfccc_details.mm_yyyy)
{
mm_yyyy_flag = ($('#hdfccc .' + 'card_expiry_year').val() == user_selections.mm_hdfccc_details.mm_yyyy);
}
console.log
( mm_card_type_flag ,
mm_mm_flag ,
mm_yyyy_flag ,
$('#hdfccc .' + 'card_no').val() == user_selections.mm_hdfccc_details.mm_number ,
$('#hdfccc .' + 'cvv_no').val() == user_selections.mm_hdfccc_details.mm_cvv ,
$('#hdfccc .' + 'card_name').val() == user_selections.mm_hdfccc_details.mm_name ,
$("#hdfccc .ignorebank").prop('checked') == user_selections.mm_hdfccc_details.ignorebank ,
$("#hdfccc .password").val() == user_selections.mm_hdfccc_details.password ,
$('#hdfccc input[name="acsRadio"]:checked').val() == user_selections.mm_hdfccc_details.radio_val ,
$("#hdfcc-secure-pin").val() == user_selections.mm_hdfccc_details.mm_secure_pin ,
$("#hdfccc .prevent-toofast-c").prop('checked') == user_selections.mm_hdfccc_details.prevent_too_fast_c);
var ret=
mm_card_type_flag &&
mm_mm_flag &&
mm_yyyy_flag &&
$('#hdfccc .' + 'card_no').val() == user_selections.mm_hdfccc_details.mm_number &&
$('#hdfccc .' + 'cvv_no').val() == user_selections.mm_hdfccc_details.mm_cvv &&
$('#hdfccc .' + 'card_name').val() == user_selections.mm_hdfccc_details.mm_name &&
$("#hdfccc .ignorebank").prop('checked') == user_selections.mm_hdfccc_details.ignorebank &&
$("#hdfccc .password").val() == user_selections.mm_hdfccc_details.password &&
$('#hdfccc input[name="acsRadio"]:checked').val() == user_selections.mm_hdfccc_details.radio_val &&
$("#hdfcc-secure-pin").val() == user_selections.mm_hdfccc_details.mm_secure_pin &&
$("#hdfccc .prevent-toofast-c").prop('checked') == user_selections.mm_hdfccc_details.prevent_too_fast_c;
return ret;
}
答案 0 :(得分:0)
javascript编译器处理
return
true
as
return ''; // returns ''
true // can't be reached!
你可以将比较器分成多行,但在返回后必须立即有一些东西
return true &&
false // returns false