Example of a circular reference in Javascript?

前端 未结 8 857
说谎
说谎 2020-11-27 16:36

I was wondering if anyone has a good, working example of a circular reference in javascript? I know this is incredibly easy to do with closures, but have had a hard time wr

8条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 17:40

    function circular(arg){
        var count = 0;
    
        function next(arg){
            count++;
            if(count > 10) return;
            if(arg){
                console.log('hava arg: ' + arg);
                next();
            }else{
                console.log('no arg');
                next('add');
            }
        }
        next();
    }
    circular();
    

    Circular and with a closures.

提交回复
热议问题