2021-04-13
作者:互联网
<!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>
<script>
// 1.利用 new Object()创建对象
var obj1 = new Object();
// 2.利用 对象字面量创建对象
var obj2 = {};
// 3.利用构造函数创建对象
function Star(uname,age){
this.uname = uname;
this.age = age;
this.sing = function(){
console.log("我会唱歌");
}
}
var ldh = new Star('刘德华',19);
var zxh = new Star('张学友',20);
ldh.sing();
zxy.sing();//都输出的为"我会唱歌"
</script>
</body>
</html>
<!--
1) new 的作用 新建一个空对象
2) 让this指向这个新的对象
-->
标签:13,Star,04,创建对象,uname,2021,sing,var,new 来源: https://blog.csdn.net/weixin_41033048/article/details/115682657