您好,登录后才能下订单哦!
密码登录
            
            
            
            
        登录注册
            
            
            
        点击 登录注册 即表示同意《亿速云用户服务条款》
        本篇内容主要讲解“Javascript 的caller,callee,call,apply怎么使用”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Javascript 的caller,callee,call,apply怎么使用”吧!
// caller demo {function callerDemo() {	if (callerDemo.caller) {		var a= callerDemo.caller.toString();		alert(a);	} else {		alert("this is a top function");	}}function handleCaller() {	callerDemo();}需要注意的是callee拥有length属性,这个在有的时候用于验证还是比较好的。
function calleeDemo() {	alert(arguments.callee);}function calleeLengthDemo(arg1, arg2) {	if (arguments.length==arguments.callee.length) {		window.alert("验证形参和实参长度正确!");		return;	} else {		alert("实参长度:" +arguments.length);		alert("形参长度: " +arguments.callee.length);	}}		// simple call demofunction simpleCallDemo(arg) {	window.alert(arg);}function handleSPC(arg) {	simpleCallDemo.call(this, arg);}// simple apply demofunction simpleApplyDemo(arg) {	window.alert(arg);}function handleSPA(arg) {	simpleApplyDemo.apply(this, arguments);}	// inheritfunction base() {	this.member = "never-online";	this.method = function() {		window.alert(this.member);	}}function extend() {	base.call(this);	window.alert(member);	window.alert(this.method);}	// advanced apply demofunction adApplyDemo(x) {	return ("this is never-online, BlueDestiny '" + x + "' demo");}function handleAdApplyDemo(obj, fname, before) {  var oldFunc = obj[fname];  obj[fname] = function() {    return oldFunc.apply(this, before(arguments));  };}function hellowordFunc(args) {  args[0] = "hello " + args[0];  return args;}function applyBefore() {	alert(adApplyDemo("world"));}function applyAfter() {	handleAdApplyDemo(this, "adApplyDemo", hellowordFunc);	alert(adApplyDemo("world")); // Hello world!}	免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。