What is the substitute for arguments.callee in js strict mode

the following is a timer object that will report an error in strict mode. Does the boss know how to modify it?

var Timing = function(fun,interval){
    this.fun = fun;
    this.interval = interval*1000;
    this.timer;
}
Timing.prototype = {
    constructor: Timing,
    setTime: function(){
        var that = this;
        var fun = that.fun;
        that.timer = setTimeout(function(){
            fun();
            that.timer = setTimeout(arguments.callee,that.interval);
        },that.interval);
    },
    clearTime: function(){
        clearTimeout(this.timer)
    }
}


var time = new Timing(function(){
    console.log("hello");
},1);
time.setTime();

console error: Uncaught TypeError: "caller"," callee", and "arguments" properties may not be accessed on strict mode functions or the arguments objects for calls to them

Apr.05,2021

It's impossible to replace

, but why use anonymous functions.

        that.timer = setTimeout(function cb(){
            fun();
            that.timer = setTimeout(cb,that.interval);
        },that.interval);
There is no substitute for

.


in addition, it is recommended that you learn to use ES6's let and arrow functions instead of var and that.

Menu