对象(object)
1.利用字面量:{}
var object= {};
var object = {
uname: ’ 张珊’ ,
sayHi: function() {
console.log(‘hi~’);
}
}
<!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>
var obj = {
uname: '可可',
type: '阿拉斯加',
age: '5岁',
cole: '棕红色',
sayBark: function () {
console.log('汪汪汪');
},
showFilm: function () {
console.log('演电影');
}
}
console.log(obj.cole);
console.log(obj['uname']);
obj.sayBark();
obj.showFilm();
// new Object创建对象
var obj = Object();
obj.uname = '鸣人';
obj.sex = '男';
obj.age = '19岁';
obj.skill = function () {
console.log('分身术');
}
console.log(obj['unaem']);
console.log(obj.age);
obj.skill();
</script>
</body>
</html>
new Object
构造函数