1. 创建一个电脑对象,该对象要有颜色、重量、品牌、型号、可以看电影、听音乐、打游戏和敲代码。
// 方式:利用字面量创建
var computer = {
color : 'black-red',
weight : '110g',
brand : '神舟',
type : 'x7',
make:function() {
console.log('看电影');
console.log('听音乐');
console.log('打游戏');
console.log('敲代码');
}
}
console.log(computer.color);
console.log(computer.weight);
console.log(computer.brand);
console.log(computer.type);
computer.make();
2. 创建一个按钮对象,该对象中需要包含宽,高,背景颜色和点击行为。
// 方式:new object创建
var button = new Object
button.width = '200px',
button.height = '150px',
button.bgColor = 'red',
button.onclick = function() {
console.log('点我变色');
}
console.log(button.width