caller,callee,arguments,call,apply用法以及说明

<script>
//caller 得到呼叫自己的function
function callerDemo() {
if (callerDemo.caller) {
   var a= callerDemo.caller.toString(); 
   alert(a); 
} else { 
     alert("this is a top function"); 
}
}

function handleCaller() {
   callerDemo();
}
//callerDemo()
//handleCaller()

//arguments 获得 当前方法需要的参数个数
//arguments.callee 获得当前方法
//arguments.callee.length 获得当前方法传入参数的可是
function calleeDemo() { 
alert(arguments.callee);
}
function calleeLengthDemo(arg1, arg2){
     alert(arguments.callee.length)
if (arguments.length==arguments.callee.length) { 
   window.alert("验证形参和实参长度正确!"); 
   return; 
} else { 
   alert("实参长度:" +arguments.length); 
   alert("形参长度: " +arguments.callee.length); 
}
}
//calleeDemo()
//calleeLengthDemo(10)


//用于实现function 的继承
function simpleCallDemo(arg) {
window.alert(arg);
}
function handleSPC(arg) {
//把simpleCallDemo的所有方法赋值给当前对象 
//参数根据simpleCallDemo的个数加
simpleCallDemo.call(this, arg);
}
//handleSPC("111")
function simpleApplyDemo(arg) {
window.alert(arg);
}

function handleSPA(arg) {
//把simpleApplyDemo 的所有方法赋值给当前对象
//参数为当前对象的参数(数组)
simpleApplyDemo.apply(this, arguments);
}
//handleSPA("111")

//实现对象的继承
var test = {
value : 'default',
exec : function(){
alert(this.value);
}
}
function hhh(obj){
test.exec();
test.exec.apply(obj);
}

</script>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值