js 運算符優先級

運算符優先級:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Operator_Precedencejavascript

<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>運算符優先級</title>
    </head>
    <body>
        <script type="text/javascript">
            /* eslint-disable */
            function Foo() { getName = function() { console.log(1) } return this; } Foo.getName = function() { console.log(2) } Foo.prototype.getName = function() { console.log(3) } var getName = function() { console.log(4) } function getName() { console.log(5) } // 輸出2 調用類的靜態方法Foo.getName
            // Foo.getName()

            // 輸出4 function getName()會進行提高,以後被var getName從新複製
            // getName()

            // 輸出1 實例的方法
            // Foo().getName()

            // 輸出2 new運算符的優先級低於.
            // new Foo.getName()

            // 輸出3 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Operator_Precedence 
            // 就是考察運算符優先級 我是不會這樣寫的 傷腦
            new Foo().getName() // 輸出3 輸出3 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Operator_Precedence 
            // 就是考察運算符優先級 我是不會這樣寫的 傷腦
            // new new Foo().getName()
        </script>
    </body>
</html>
相關文章
相關標籤/搜索