Skip to content
Akin C edited this page Apr 15, 2018 · 9 revisions

Welcome to the Javascript-closures-fact-three- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


Closures are not supported in all programming languages, but they are in Javascript. It seems to understand them, it is necessary to look at three facts about closures.

This is the third one and the others can be found here:

Fact three says that a variable which is defined in an outer function can be updated. For example

function anyFunction()
{
    //Similar to a member variable
    var varOutside = undefined;
    
    return {
        //Similar to methods
        setValue: function(newValue)
        {
            varOutside = newValue;
        },
        getValue: function()
        {
            return varOutside;
        }
    };
}

var myObject = anyFunction();
myObject.setValue(1000);//Updating value
console.log( myObject.getValue() );//Outputs 1000

Content

The user interaction part should look like the content as seen below by starting "index.html" in a web browser.

ERROR: No image found!

The essential part of the program relevant to fact three is found in "closures.js".

The colored areas in the heading "Get Features" are just for a better readability in the wiki and are not part of the content. To use the project just download the files and execute "index.html". Note that all files should be placed in the same folder so that the functionality of the code is guaranteed.

Clone this wiki locally