36 lines
932 B
HTML
36 lines
932 B
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Document</title>
|
|
</head>
|
|
|
|
<body>
|
|
|
|
</body>
|
|
<script>
|
|
//类的本质就是对象
|
|
class PicturePreview {
|
|
constructor(text) {//如果不写text 那么打印出来 “我是构造函数 undefined”
|
|
//this //通过this定义一个
|
|
this.a = text;
|
|
//console.log("我是构造函数", text);//如果不写text 你好不会被打印
|
|
console.log("我是构造函数", this.a);
|
|
}
|
|
|
|
getA() {
|
|
console.log(this.a);
|
|
}
|
|
}
|
|
var text = new PicturePreview("你好")//如果不写new “constructor”不执行 console.log也不会打印
|
|
|
|
//console.log(text);//打印出来是PicturePreview {}
|
|
|
|
text.getA()
|
|
|
|
</script>
|
|
|
|
</html> |