javascript - For example, the function name is f1, the difference between f1 and f1()
仅有的幸福
仅有的幸福 2017-06-26 10:56:29
0
2
772

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>    
    <h2>DOM 2级事件绑定</h2>
    
    <button>解绑</button>

    <script type="text/javascript">
    
        var h2 = document.getElementsByTagName('h2')[0];
        function f1(){
            console.log('甲程序员的小功能');
        }
        //甲程序员
        h2.addEventListener('click',f1);

        //解绑
        var btn = document.getElementsByTagName('button')[0];
        btn.onclick = function(){
            h2.removeEventListener('click',f1);
        }
        
        //乙程序员
        h2.addEventListener('click',function(){
            console.log('乙程序员的小功能');
        });

        //丙程序员
        h2.addEventListener('click',function(){
            console.log('丙程序员的小功能');
        });

        
    
    </script>
</body>
</html>
仅有的幸福
仅有的幸福

reply all(2)
ringa_lee

f1 is the function object itself. The function is equivalent to assigning the function object to the variable of the function name, so you can access the function just like accessing the variable.
f1() is the calling function.

function test() { console.log('hello'); }
function callfun(f) { f(); } // Pass function `f` and call it in the function.
callfun(test);   // Call `test` and print 'hello'
扔个三星炸死你

f1() gets the return value of the function call, and f1 represents the pointer to a function

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template