全局对象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>