
var CALLBACK = (function() {
    var
        /** @type {Object<string, Function>} */
        callbacks = {},
        /** @type {number} */
        currentCallbackId = 0;

    /** @type {function(Function, Object=):number} */
    function makeCallback(fnc, ctx) {
        var cbId = currentCallbackId++;
        if (ctx)
            fnc.ctx = ctx;
        callbacks['' +cbId] = fnc;
        return cbId;
    }

    function triggerCallback() {
        var id = '' +Array.prototype.shift.call(arguments);
        if (callbacks[id]) {
            callbacks[id].apply(callbacks[id].ctx, arguments);
            delete callbacks[id];
        }
    }

    return {
        /** @type {function(Function, Object=):number} */
        makeCallback: makeCallback,
        onCallbackResponse: triggerCallback
    };
})();

window["__CALLBACK"] = { "onResult": CALLBACK.onCallbackResponse };

/** @return {boolean} */
function isNative() {
    return !!("__native" in window);
}

