Skip to content

Commit

Permalink
Update Object.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yihan12 authored Dec 14, 2023
1 parent 1134f0d commit 586dbbd
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion javascript/Data Types/Object.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,31 @@
- Functions
- Objects

### 创建对象
### 创建对象四种方法
- 使用构造函数
- 使用对象字面量
- 使用Object.create()方法创建对象
- 使用es6 Class

#### 使用构造函数
```javascript
function vehicle(name,maker,engine){
this.name = name;
this.maker = maker;
this.engine = engine;
}

let car = new vehicle('GT','BMW','1998cc');
// OUTPUT: vehicle {name: 'GT', maker: 'BMW', engine: '1998cc'}
// GT
// BMW
// 1998cc
console.log(car);
console.log(car.name);
console.log(car.maker);
console.log(car['engine']);
```

```javascript
const o = new Object();
o.foo = 42;
Expand Down

0 comments on commit 586dbbd

Please sign in to comment.