var obj = {
name: '可可',
type: '阿拉斯加犬',
age: '5',
color: 'red',
bark: function () {
console.log('汪汪汪');
},
show: function () {
console.log('演电影');
}
}
// 利用等号= 赋值的方法 添加对象的属性和方法
// 每个属性和方法之间用分号结束
console.log(obj.name);
console.log(obj.age);
console.log(obj['color']);
obj.bark;
// 利用new object创建对象
var objs = new Object(); // 创建了一个空的对象
objs.uname = '张三疯';
objs.age = 18;
objs.sex = '男';
objs.hai = function () {
console.log('hi~');
}
console.log(objs.uname);
console.log(objs['sex']);
objs.hai();
var ming = new Object();
ming.name = '鸣人';
ming.sex = '男';
ming.age = 19;
ming.skill = function () {
console.log('影分身术!');
}
console.log(ming.name);
console.log(ming['sex']);
console.log(ming.age);
ming.skill();
var mingr = {
name: '鸣人',
sex: '男',
age: 18,
skill: function () {
console.log('影分身术!');
}
}
console.log(mingr.name);
console.log(mingr['sex']);
console.log(mingr['age']);
mingr.skill();
这篇文章还没有评论