<!DOCTYPE html><html><head><title>01_define.html</title><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="this is my page"><metahttp-equiv="content-type"content="text/html; charset=UTF-8"><!--<link rel="stylesheet" type="text/css" href="./styles.css">--><scripttype="text/javascript">
console.log('this关键字');
//当需要创建一个类的时候,设置类的属性和方法要用this关键字来引用//但是特别注意:this关键字在调用的时候会根据不同的调用对象变得不同var color = 'red';
functionshowColor(){
console.log(this.color);
}
//创建了一个类,有一个属性和方法functionCircle(color){this.color = color;
this.showColor = showColor;
}
var c = new Circle('yellow');
//用c来调用showColor等于是调用了showColor()方法,此时的this是c,所以color就是yellow
c.showColor(); //yellow//此时调用的对象是window,showColor的this就是window,所以就会找window中的color
showColor(); //red</script></head><body>
This is my HTML page. <br></body></html>