DEV Community

Discussion on: Getters And Setters used in JavaScript Objects....How?

Collapse
 
dreplica profile image
dreplica • Edited

/also to hide/encapsulate your details and to input details in either function invocation or using get/set/

function details (){
var name;
var age;

for (var i=0; i<arguments.length; i++){
var arc = arguments[i];
if(typeof arg[0] !== "string") throw " invalid first argument ";

if(typeof arg[1]!==" number") throw "invalid second argument";
};

return {get: function () {return this.name+ " is " +this.age;},
set: function (name, age){
this.name = name;
this.age = age;

}

}

}

var personal_details = details ();

personal_details.set(" Dreplica "," gg");

console.log(details())