当前位置:网站首页>Function executes only the once function for the first time

Function executes only the once function for the first time

2022-04-23 13:47:00 Everything wins sy


// Execute the function only once 
    function once(fn){
    
        var ifFalse = true
        return function(){
    
            if(ifFalse){
    
                ifFalse = false
                fn()
            }
        }
    }
    // call 
    function getName(){
    
        console.log(' My name is Chihuahua ')
    }
    getName = once(getName)
    getName() //' My name is Chihuahua '
    getName() // Don't execute 

From the link :https://www.nowcoder.com/questionTerminal/42997185c50a45a08b64c253d2f1edc5?mutiTagIds=644&page=1&onlyReference=false

版权声明
本文为[Everything wins sy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231336214400.html