开发者

Correct way to fill un-needed callbacks in javascript

Consider this code snippet:

transaction.executeSql(  
'SELECT * FROM pv_master;', [],  
    function(transaction, result) {  
        if(result.rows.length == 0) {  
        jQT.goTo("#register", 'slideup');  
        }  
    }, errorHandler  
);

This example is a little different to the question title as the square brackets should be filled with some value.

Ima开发者_StackOverflow中文版gine I didn't want a success callback but did want a failure callback, which comes second in this instance.

What would be the correct way to go about it?


In this case, you can simply put null, since the algorithm checks for this. I wrote a simple demo a while back that does this. If the function didn't check, you would pass an empty function:

function(){}

Note that you wouldn't need to worry about the parameter count, since it's okay to call a JS function with too many parameters.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜