Найдите образец шаблона объекта для вашего Java. Сценарий:
var Man=function(n,a){
var name,age;
function getName(){
return this.name;
}
function getAge(){
return this.age;
}
function create(){
this.name=n;
this.age=a;
console.log('new object created');
}
function setAge(age){
this.age=age;
}
function setName(name){
this.name=name;
}
return{
name:n,
age:a,
getName:getName,
getAge:getAge,
setName:setName,
setAge:setAge
};
}
var m1=new Man('Chaiguy',30);
// To check if Property exist for an Object
console.log(m1.hasOwnProperty('name'));
// To get the name and age of the object
console.log(m1.getName()+' is '+m1.getAge()+' years old.');