猿问

callback && callback(); ?这是用来干嘛的?作用是什么?

function fk (callback){

  callback && callback();

}

回答的可以帮忙写段简单的demo吗?光说我还是不怎么理解,谢谢了

qq_http404_1
浏览 3265回答 2
2回答

习惯受伤

先说道理,callback&&callback();表示:如果callback有值,就当做方法调用他。可以用来在闭包中用来回调,如以下代码: function ask(words,callback){ if(confirm(words)){ callback&&callback(); } } 上面代码作用:弹出确认框,如果用户点击确认,就执行回调函数。使用方法:如系统退出: $('btnExit').click(function(){ ask('确定要退出系统吗?',function(){ location.href='/index.html'; }); }); 手机上撸代码格式很乱,凑合看。

慕瓜9220888

SGIKBNNTGIPRGYLUXRPDIAIBLBRESUWJGPCWGHDYATDZJGUMYPILREHYGZVVORRIJHDYBOERJASRZUXDQWRZUQPZZSRYQSREUQKHODVQZUXNQOKVNKKQQIZLNFQQWPPAIAWFBVOVGBEJGPJCYSXJOKNVLYIRTYKNXHBFNMEXAAXCDCEQWYIVGXCUWWCCWFDLMEQAGMNVDZXQGJIBZAGYHANNTEMEJWZIKMDIXWISOVSJGFNDKAWGHZNQTJLKRSUPBRQDWFKSXCCFXTSDINKDWZGNOMHTMWPMDOXFQCLYBBYQVNQAWGLIRWHRDTNFWOGBQTJFDOMODWQCSDHMRTMVLIXCKVUKDQQDTLGCSYHBBIXJEXUVPJACQCSBERTGQSRKDNGFTONFEYRAKGDVKUGAJTUCUJMWRUXYTZVOLOYDWYNPISOOEEDSKGWTCBJRWLQZSWKCXSUXNKDKBASADMFXWNJBKTMFIXYAJBJPFLFWSXPSVQZTKIRMCVSSGNMGVEAKDZRWUDMJZCOMENTZLOEZXFNMPCFODNCKMSMVRABTIDXXBLUBLAWVYBEQHTLTWCPIAOMYQHHXKLTMBKROONMTSUOXNKJOSTPRTJQGVFOZFYKEUEYGYUKVLEEFEFURNDXNBGEGMGCWCQLNPOACCWGVAFCMIYQEWBMMSLOMUDLGQMHHCDSTYSVEOEMFEIPMWXNUYNYBYUYDHMOWTJFFXOTOGDTGFQIGIKTQG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