자바스크립트에서 기본값 부여(객체로 넘김)

2013년 4월 2일 at 1:50 pm


function test(options) {
if (options == undefined) options = {};
if (options.name == undefined) options.name = "기본 도형";
if (options.width == undefined) options.width = 10;
if (options.height == undefined) options.height = 10;
}

test({
name : "도형1",
width : 10,
height : 20
});

test({
name : "도형2"
});