converting code from non-(C)ontinuation (P)assing (S)tyle to CPS

Posted by Delirium tremens on Stack Overflow See other posts from Stack Overflow or by Delirium tremens
Published on 2010-03-12T17:03:32Z Indexed on 2010/03/12 17:07 UTC
Read the original article Hit count: 227

Filed under:
|
|

before:

function sc_startSiteCompare(){
    var visitinguri;
    var validateduri;
    var downloaduris;
    var compareuris;
    var tryinguri;
    sc_setstatus('started');
    visitinguri = sc_getvisitinguri();
    validateduri = sc_getvalidateduri(visitinguri);
    downloaduris = new Array();
    downloaduris = sc_generatedownloaduris(validateduri);
    compareuris = new Array();
    compareuris = sc_generatecompareuris(validateduri);
    tryinguri = 0;
    sc_finishSiteCompare(downloaduris, compareuris, tryinguri);
}
function sc_getvisitinguri() {
    var visitinguri;
    visitinguri = content.location.href;
    return visitinguri;
}

after (I'm trying):

function sc_startSiteCompare(){
    var visitinguri;
    sc_setstatus('started');
    visitinguri = sc_getvisitinguri(sc_startSiteComparec1);
}
function sc_startSiteComparec1 (visitinguri) {
    var validateduri;
    validateduri = sc_getvalidateduri(visitinguri, sc_startSiteComparec2);
}
function sc_startSiteComparec2 (visitinguri, c) {
    var downloaduris;
    downloaduris = sc_generatedownloaduris(validateduri, sc_startSiteComparec3);
}
function sc_startSiteComparec3 (validateduri, c) {
    var compareuris;
    compareuris = sc_generatecompareuris(downloaduris, validateduri, sc_startSiteComparec4);
}
function sc_startSiteComparec4 (downloaduris, compareuris, validateduri, c) {
    var tryinguri;
    tryinguri = 0;
    sc_finishSiteCompare(downloaduris, compareuris, tryinguri);
}
function sc_getvisitinguri(c) {
    var visitinguri;
    visitinguri = content.location.href;
    c(visitinguri);
}

I'm having to pass lots of arguments to functions now. global in procedural code look like this / self in modular code. Any difference? Will I really have to use OO now? As a last resort, does CPS have an alternative?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about cps