<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>javascript的对象</title>
</head>
<body>
<script>
let car = new Object();
car.brand = 'qq';
car.color = 'black';
car.move = function () {
console.log('the car is moving');
}
console.log(car.brand);
console.log(car.color);
car.move();
let car2 = new Object();
car2.brand = 'qq';
console.log(car2.color); //未定义
let car3 = {};
car3.brand = 'qq';
car3.color = 'black';
car3.move = function () {
console.log('the car is move');
}
console.log(car3.brand);
console.log(car3.color);
car3.move();
let car4 = function () {
this.brand = 'qq';
this.color = 'green';
this.move = function () {
console.log('the car is moving');
}
}
let c = new car4();
console.log(c.brand);
console.log(c.color);
c.move();
let bmw = new Object();
bmw.brand = 'bmw';
bmw.color = 'white';
bmw.move = function () {
console.log('the car is moving');
}
let qq = Object.create(bmw);
qq.brand = 'qq';
qq.color = 'red';
console.log(qq.brand);
console.log(qq.color);
qq.move();
</script>
</body>
</html>
vue-案例教程第4章02.html
最新推荐文章于 2024-06-10 22:18:41 发布