全局对象this转为局部对象

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script>
    var name = "aa";
    var person = {
        name: "bb",
        hello: function(){
            var _self = this;
            function sayHello(){
                console.log(this);
         //Window {speechSynthesis: SpeechSynthesis, caches: CacheStorage, localStorage: Storage, sessionStorage: Storage, webkitStorageInfo: DeprecatedStorageInfo…} alert(_self.name);
         //bb } sayHello(); } } person.hello();
</script> </body> </html>

 

posted @ 2016-12-02 09:10  文道诗洋  阅读(136)  评论(0编辑  收藏  举报