<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script type="text/javascript"> var name = ‘this is window‘; //定义window的name属性,看this.name是否会调用到 var testObj = { name:‘this is testObj‘, getName:function(){ console.log(this); //控制台输出:testObj //this指向的是testObj对象 console.log(this.name); //控制台输出: this is testObj } } testObj.getName(); </script> </body> </html>
时间: 2024-12-13 02:58:05