How do I tell if my Javascript code is running in Jint?

188 Views Asked by At

I've designed some functions which call alert() and confirm().

I use Jint to test those functions.

However, Jint doesn't support alert() and confirm().

What I'd like to do is create a wrapper around alert() and confirm() which checks if running in Jint context:

function MyAlert()
{
    if(Jint != true) alert();
}

How do I tell if I'm in Jint context?

Thanks, Ed

1

There are 1 best solutions below

0
On

Rather than environment detection, I'd suggest feature detection:

function MyAlert(msg) {
    if (typeof alert !== "undefined") { // *
        alert(msg);
    }
}

* or === "function", but some older browsers (like IE8, still sadly in significant-though-diminishing use) report built-ins like alert as "object".