call 和 apply 的用法

<script type="text/javascript">
function call1() {
this.addr = "china";
this.getAddr = function () {
return this.addr;
}
}
function call2() {
this.addr = "zhejiang";
this.setAddr = function (addr) {
this.addr = addr;
}
}

var a = new call1();
var b = new call2();
b.setAddr.call(a,
"hangzhou");
alert(a.getAddr());
</script>


<script type="text/javascript">
function T1(a, b, c, d) {
alert(a
+b+c+d);
}
function T2(a,b,c,d) {
T1.apply(
this, [a,b,c,d]);
}
T2(
"a","b",3,65);
</script>

  

posted @ 2011-08-06 13:46  sirzxj  阅读(148)  评论(0编辑  收藏  举报