함수의 호출
function.apply();//내장된 함수인 경우 native code라고 나온다.
function sum(arg1, arg2) {
return arg1+arg2;
}
sum.apply(null, [1,2]);//3
sum.apply(null, [4,2]);//6o1 = {val1 : 1, val2 : 2, val3 : 3}
o2 = {v1 : 10, v2 : 50, v3 : 100, v4:25}
function sum() {
var _sum = 0;
//var this = o1;
for(name in this) {//o1이 this로 전달된다.
_sum += this[name];
}
return _sum;
}
alert(sum.apply(o1));//o1.sum()이 된다(o1객체의 메소드가 된다!)
alert(sum.apply(o2));//o2.sum()이 된다(o2객체의 메소드가 된다!)Last updated