js的constructor callee caller

本文探讨了JavaScript中子类继承父类的方法,并通过实例展示了如何实现方法的重写及调用。此外,还介绍了如何使用函数自身的引用进行递归调用以计算阶乘。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script type="text/javascript">
var name ="window method";
function parentClass() {
    this.name = "parentClass method";
    this.method = function() {
        alert(this.name);
    }
}
function subClass() {
    //var method = this.method;
    //this.name ="test";
    this.method = function() {
        //method.call(this);//如果不用这一步而用下面的就会调用的是window.name;
        //method();
        alert("subClass method");
    }
}
subClass.prototype = new parentClass();
//subClass.prototype.constructor = subClass;

var o = new subClass();
//alert(o.constructor);
o.method();
function ssonClass(){
    o.constructor.call(this);
};
var h = new ssonClass();
h.method();
function CallLevel(){
   if (CallLevel.caller == null){
        return("CallLevel was called from the top level.");
   }
   else{
        return("CallLevel was called by another function.");
   }
};
alert(CallLevel());
function test(){
    alert(CallLevel());
}
test();
function factorial(n){
  if (n <= 0){
    return 1;
  }
  else{
    return n * arguments.callee(n - 1);//callee是对函数自身的引用
  }
}
alert(factorial(3));
</script>
为啥自定义校验// 提取出来的密码校验函数 const validatePasswordMatch = (rule: any, value: string, callback: Function) => { console.log('rule:',rule) console.log('value:',value); console.log('callback:',callback); if (!formModel.value.password) { callback(new Error('密码不能为空')) } else if (value !== formModel.value.password) { callback(new Error('两次密码输入不一致')) } else { callback() // 校验通过 } }rule: 123 forgetPsw.vue:51 value: Proxy(Object) {trigger: 'blur', validator: ƒ}[[Handler]]: MutableReactiveHandler[[Target]]: Objecttrigger: "blur"validator: (rule, value, callback) => {…}length: 3name: "validatePasswordMatch"arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at validatePasswordMatch.invokeGetter (<anonymous>:3:28)]caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at validatePasswordMatch.invokeGetter (<anonymous>:3:28)][[FunctionLocation]]: forgetPsw.vue:49[[Prototype]]: ƒ ()[[Scopes]]: Scopes[3][[Prototype]]: Objectconstructor: ƒ Object()hasOwnProperty: ƒ hasOwnProperty()isPrototypeOf: ƒ isPrototypeOf()propertyIsEnumerable: ƒ propertyIsEnumerable()toLocaleString: ƒ toLocaleString()toString: ƒ toString()valueOf: ƒ valueOf()__defineGetter__: ƒ __defineGetter__()__defineSetter__: ƒ __defineSetter__()__lookupGetter__: ƒ __lookupGetter__()__lookupSetter__: ƒ __lookupSetter__()__proto__: (...)get __proto__: ƒ __proto__()set __proto__: ƒ __proto__()[[IsRevoked]]: false forgetPsw.vue:52 callback: undefined
最新发布
03-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值