6
Is it possible to make an object in js/jQuery where it is visible only using the method, for example get / set? An example of an object:
if I give a console.log(pessoa.documeto)
, it will display the values, but what I wanted is to see if there is a way to make it 'private' or 'protected' equal to PHP and others.
var pessoa = {
nome : '' , //Publico
idade : '' , //Publico
documentos : [
//Protegido / Privado
{
CPF : {
num : '' ,
dataemissao : '' ,
ufemissao : '' ,
obrigatorio : true ,
status : ''
} ,
RG : {
num : '' ,
dataemissao : '' ,
ufemissao : '' ,
obrigatorio : '' ,
status : false
}
}
] ,
parentes : [
{
pai : {
nome : '' ,
idade : '' ,
cpf : '' ,
} ,
mae : {
nome : '' ,
idade : '' ,
cpf : '' ,
},
irmaos : [
{
nome : '' ,
idade : '' ,
cpf : ''
}
]
}
] ,
//Metodos
get : function(propriedade){
/*
* Pega a propridade e tal,
* mas nao vou descrever isso aqui agora =D
*/
} ,
set : function(proriedade , valor){
/*
* Seta a propriedade e bla, bla, bla...
*/
}
};
With literal object does not give, but it is possible to achieve something similar with the module Pattern.
– bfavaretto
Hmm, so I’ll have to take a look at some framework for JS/jQuery or create a function that would be class (PHP) and other functions inside that would be something like the methods. that ?
– Douglas Dreer