I am completely new to javascript. I saw the below snippet in a tutorial. But i am not sure why do we use funtionName: function in return statement.
For example, getID:function() and setID: function() in the below code. Can anybody explain.
function celebrityID () {
var celebrityID = 999;
return {
getID: function () {
return celebrityID;
},
setID: function (theNewID) {
celebrityID = theNewID;
}
}
}
celebrityIDfunction is returning an object with two properties which are functions and can be invoked later. Simple.getandsetthecelebrityIDlike so.var celebrity = celebrityID()andcelebrity.getID()orcelebrity.setID(20000)