打赏

javascript this指向

<!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>javascript this指向</title>

    </head>

    <body>
        <script type="text/javascript">
            var a = {
                name: 'mfg'
            }

            function test() {
                console.log(this)
            }
            test(); //指向window
            new test(); //指向test()
            test.call(a); //指向a
        </script>
    </body>

</html>

 

posted @ 2018-04-04 11:46  孟繁贵  阅读(113)  评论(0编辑  收藏  举报
TOP