创建对象的三种方式
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
//系统内置创建对象函数
var cmp = new Object();
cmp.color = '黑色';
cmp.weight = '3kg';
cmp.logo = '联想';
cmp.type = '血骑士';
cmp.music = function () {
console.log("偶哈哈我正在听音乐");
};
cmp.play = function () {
console.log("ye我在玩游戏");
}
cmp.work = function () {
console.log("我在工作,敲代码中呢");
}
// 自定义构造函数(类)创建对象
// function Cmp(color,weight,logo,type) {
// this.color = color;
// this.weight = weight;
// this.logo = logo;
// this.type = type;
// this.music = function () {
// console.log("我在用"+this.color+'的电脑嗨皮呢');
// };
// this.play = function () {
// console.log("我在用"+this.weight+'的'+this.logo+this.type+'电脑打游戏');
// }
// this.work = function () {
// console.log('我的电脑随时可以工作');
// }
// }
// var cmp = new Cmp('红色','3kg','联想','血骑士');
// cmp.play();
//字面量创建构造函数
var student = {
name:"我的天哪",
age:17,
sex:"男"
};
console.log("我已经"+student.age+'岁了');
</script>
</head>
<body>
</body>
</html>