O'Reilly logo

Game Programming using Qt 5 Beginner's Guide - Second Edition by Lorenz Haas, Witold Wysota, Pavel Strakhov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Global object state

Let's try another script. The following code defines the fun local variable, which is assigned an anonymous function that returns a number:

var fun = function() {
    return 42;
}

You can then call fun() like a regular function, as follows:

Now, let's look at what happens if we delete the definition of fun from the script, but still keep the invocation:

We still get the same result even though we didn't define what fun means! This is because any variables at the top scope become properties of the global object. The state of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required