Notice
Recent Posts
Recent Comments
Link
«   2024/10   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter06 : 생성자함수 본문

WEB.JS/06.객체_JS

chapter06 : 생성자함수

GAWON 2023. 5. 19. 17:42
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
/*
생성자 함수

```
  1. 객체를 생성하는 함수
  2. 첫 글자를 대문자로 만든다. ★★★

  ex) 기존 book 객체 생성
     var book = {};

     생성자 함수를 통한 객체생성 - 1
     function Book(){}
     var book = new Book();

     생성자 함수를 통한 객체 생성 - 2
     function BOok(title){ this.title = title; }
     var book = new Book("자바스크립트 정석");

```

- /

//1. 생성자 함수 정의
function Book(title , price){
this.title = title;
this.price = price;
}

[//2.생성자](https://2.xn--9g4b2f74p/) 함수를 이용한 객체 생성
var book = new book("자바스크립트 정석" , 30000);

[//3.객체](https://3.xn--i49a113d/) book의 정보 확인
for(var p in book){
document.write("<h3>" + book[p] + "</h3>");
}

</script>
</head>
<body>

</body>
</html>

'WEB.JS > 06.객체_JS' 카테고리의 다른 글

chapter07 : 객체문제  (0) 2023.05.22
chapter05 : 객체  (0) 2023.05.19
chapter04 : 객체  (0) 2023.05.19
chapter03 : 객체  (0) 2023.05.19
chapter02 : 객체  (0) 2023.05.19