<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document<title>
<script>
//构造函数和对象 的关系
//1.构造函数 明星 泛指的某一大类 它类似于java语言里面的 类(class)
function Star(uname, age, sex) {
this.name = unmae;
this.age = age;
this.sex = sex;
this.sing = function (song) {
console.log(song);
}
}
//2.对象 特指 是一个具体的事物 刘德华=={name:"刘德华",age:18,sex:"男",sing:f}
var ldh = new Star('刘德华', 18, '男');
console.log(ldh);
//3.我们利用构造函数创建对象的过程我们也称为对象的实例化
</script>
</head>
<body>
</body>
</html>
2021-07-24 JavaScript 构造函数和对象 的关系
最新推荐文章于 2023-05-16 22:40:39 发布