[JavaScript] 기존 Object 에 변수나 함수 추가하기
아래와 같은 objectA 가 있다고 하자.
var objectA = {
arrayA = [],
functionA : function() {
return "A";
}
}
objectA 에 arrayB 라는 변수를 추가하려면 다음과 같이 하면 된다.
objectA.arrayB = [];
arrayB가 있다면 추가하지 않고, 없는 경우에만 추가하고싶다면,
if(objectA.arrayB == null) {
objectA.arrayB = [];
}
위와 같이 감싸면 된다.
함수도 똑같다.
objectA.functionA = function() { return "B" };
위와 같이 하면 funtionA "A"가 아닌 "B"를 돌려준다.
Congratulations @navi-kim! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Do not miss the last post from @steemitboard:
Vote for @Steemitboard as a witness to get one more award and increased upvotes!