SoFunction
Updated on 2025-04-10

JavaScript information encapsulation Getting started with js objects


function Person()
{
/*
* Declare private data
* Nickname, age, email address
*/
var nickName, age, email;
/*
* Methods that require access to private data (privileged method)
* Each instance generated will generate a new copy for the privileged method
*/
= function(pNickName, pAge, pEmail)
{
nickName = pNickName;
age = pAge;
email = pEmail
};
= function()
{
return [nickName, age, email];
}
}
/*
* Methods that do not require direct access to private data (public method)
* No matter how many instances are generated, only one public method exists in memory
*/
= {
showData: function()
{
alert("Personal Information:" + ().join());
}
}