Search code examples
javascriptstringexceptionwarningsidentifier

JavaScript warning on var element


Have defined:

var ru_cryptopro_npcades_10_native_bridge = {

    callbacksCount : 1,
    callbacks : {},

    resultForCallback : function resultForCallback(callbackId, resultArray) {

        var callback = ru_cryptopro_npcades_10_native_bridge.callbacks[callbackId];

        if (!callback) return;

        callback.apply(null, resultArray);

    },

    call : function call(functionName, args, callback) {

        var hasCallback = callback && typeof callback == "function";
        var callbackId = hasCallback ? ru_cryptopro_npcades_10_native_bridge.callbacksCount++ : 0;

        if (hasCallback) ru_cryptopro_npcades_10_native_bridge.callbacks[callbackId] = callback;

        var iframe = document.createElement("IFRAME");
        var arrObjs = new Array("_CPNP_handle");

        try {

            iframe.setAttribute("src", "cpnp-js-call:" + functionName + ":" + callbackId+ ":" + encodeURIComponent(JSON.stringify(args, arrObjs)));

        }
        catch(e) {

            alert(e);

        }

        document.documentElement.appendChild(iframe);
        iframe.parentNode.removeChild(iframe);
        iframe = null;

    },

};

Have got such warning: Warning 1 Expected identifier or string C:\Users\Administrator\documents\visual studio 2010\Projects\WebAppSelf3\WebAppSelf3\js\CadesLoad.js 453 1 WebAppSelf3

Why?


Solution

  • Chrome parses that just fine, but I have a hunch whatever environment you have that is throwing this error doesn't like that trailing comma in your object literal.

        },
    
    };
    

    Which may need to be:

        }
    
    };
    

    Which again, is wierd, because this seem to work in at least some browsers: http://jsfiddle.net/Aa6yc/1/

    Though it's definately not good form.