Where The Streets Have No Name

Dynamically Generated Methods 본문

Developement/Web

Dynamically Generated Methods

highheat 2007. 12. 11. 15:35
객체를 생성할때 파라미터를 object로 넘김
function User( properties ) {
for ( var i in properties ) { (function(){
this[ "get" + i ] = function() {
return properties[i];
};

this[ "set" + i ] = function(val) {
properties[i] = val;
};
})(); }
}



var user = new User({
name: "Bob",
age: 44
});