简体   繁体   中英

Can one call a function from itself?

Can I do this:

function something(){

    for(x in y){
        if(x.toString() == "[object Object]"){
            something();
        }
    }

}

Yes. It's called recursion, and it's available in JavaScript. In your case, it would be infinite recursion, which would cause a stack overflow. Make sure your condition for whether it's called or not will actually change to avoid infinite recursion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM