Notice
Recent Posts
Recent Comments
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

๐ŸŒทJavaScript: ๋ฐฐ์šด ๊ฒƒ ์ค‘ ๋‹ค์‹œ ๊ธฐ์–ตํ•  ๊ฒƒ๐Ÿ˜† [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 11์ผ~18์ผ์ฐจ] ๋ณธ๋ฌธ

๐Ÿ’ปBootcamp Self-Study Revisionโœจ/JavaScript, jQuery, Ajax

๐ŸŒทJavaScript: ๋ฐฐ์šด ๊ฒƒ ์ค‘ ๋‹ค์‹œ ๊ธฐ์–ตํ•  ๊ฒƒ๐Ÿ˜† [K-๋””์ง€ํ„ธ ํŠธ๋ ˆ์ด๋‹ 11์ผ~18์ผ์ฐจ]

yjyuwisely 2023. 2. 17. 23:55

230217 Fri 

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ๊ณต๋ถ€ํ–ˆ์„ ๋•Œ ๋ฐฐ์šด ๊ฒƒ ์ค‘ ๋‚ด๊ฐ€ ํ—ท๊ฐˆ๋ คํ•˜๋Š” ๋‹ค์‹œ ๊ธฐ์–ตํ•  ๊ฒƒ์„ ์ •๋ฆฌํ–ˆ๋‹ค.

๋ชฉ์ฐจ
1) new
2) this
3) return false, return true

1) ์ƒ์„ฑ์ž ํ•จ์ˆ˜ new

2023.01.17 - [1. Revision 2023/Javascript] - [15] 230117 Ch. 9 ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ์ฒด: ๊ฐ์ฒด, ๊ฐ์ฒด์˜ ์ƒ์„ฑ ๋ฐ ์‚ฌ์šฉ, ํ”„๋กœํ† ํƒ€์ž…, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋‚ด์žฅ ๊ฐ์ฒด, Array ๊ฐ์ฒด, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ์˜ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ

์ƒ์„ฑ์ž ํ•จ์ˆ˜(Constructor Function)๋ฅผ ์ด์šฉํ•œ ๊ฐ์ฒด ์ƒ์„ฑ

์‚ฌ์šฉ์ž ์ •์˜ ๊ฐ์ฒด: ๊ฐœ๋ฐœ์ž๋Š” ์ž์‹ ๋งŒ์˜ ๊ฐ์ฒด๋„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.
์‚ฌ์šฉ์ž ์ •์˜ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋ ค๋ฉด ์ƒ์„ฑ์ž๋ผ๋Š” ํŠน๋ณ„ํ•œ ํ•จ์ˆ˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
์ƒ์„ฑ์ž๋Š” ๊ฐ์ฒด๋ฅผ ์ดˆ๊ธฐํ™”(๋ณ€์ˆ˜์— ์ œ์ผ ์ฒ˜์Œ ๋“ค์–ด๊ฐ€๋Š” ๊ฐ’ ex) var a = 10;) ํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋Š” ์—ฐ์‚ฐ์ž(์–ด๋–ค ํ•จ์ˆ˜์— ์ž‘์šฉํ•ด ๊ทธ ํ•จ์ˆ˜๋ฅผ ๋‹ค๋ฅธ ํ•จ์ˆ˜๋กœ ๋ณ€ํ˜•์‹œํ‚ค๋Š” ํ•จ์ˆ˜)๋Š” new์ด๋‹ค.

 ์ƒ์„ฑ์ž ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐ์ฒด๋ฅผ ์ •์˜ํ•˜๊ณ  new๋ฅผ ํ†ตํ•˜์—ฌ ๊ฐ์ฒด์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
An instance is a specific realization of any object in object-oriented programming.

new ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ดˆ๊ธฐํ™”ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด๋•Œ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”์„œ๋“œ๋ฅผ ์ƒ์„ฑ์ž(constructor)๋ผ๊ณ  ํ•˜๋ฉฐ,
์ด ๋ฉ”์„œ๋“œ๋Š” ์ƒˆ๋กญ๊ฒŒ ์ƒ์„ฑ๋˜๋Š” ๊ฐ์ฒด๋ฅผ ์ดˆ๊ธฐํ™”ํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์›์‹œ ํƒ€์ž…์„ ์œ„ํ•œ ์ƒ์„ฑ์ž๋ฅผ ๋ฏธ๋ฆฌ ์ •์˜ํ•˜์—ฌ ์ œ๊ณตํ•œ๋‹ค.
(์›์‹œ ํƒ€์ž…์€ ์ •์ˆ˜, ์‹ค์ˆ˜, ๋ฌธ์ž, ๋…ผ๋ฆฌ ๋ฆฌํ„ฐ๋Ÿด ๋“ฑ ์‹ค์ œ ๋ฐ์ดํ„ฐ ๊ฐ’์„ ์ €์žฅํ•˜๋Š” ํƒ€์ž…์ด๋‹ค.)

์ฐธ๊ณ : https://developer-talk.tistory.com/281

์˜ˆ์‹œ1)

var day = new Date(); // new ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Date ํƒ€์ž…์˜ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•จ.
document.write("์˜ฌํ•ด๋Š” " + day.getFullYear() + "๋…„์ž…๋‹ˆ๋‹ค.");

2) this

2023.01.17 - [1. Revision 2023/Javascript] - [15] 230117 Ch. 9 ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ์ฒด: ๊ฐ์ฒด, ๊ฐ์ฒด์˜ ์ƒ์„ฑ ๋ฐ ์‚ฌ์šฉ, ํ”„๋กœํ† ํƒ€์ž…, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋‚ด์žฅ ๊ฐ์ฒด, Array ๊ฐ์ฒด, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์—์„œ์˜ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ

this๋Š” ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ํ˜„์žฌ ๊ฐ์ฒด๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ์ƒ์„ฑ์ž๋Š” ์ „๋‹ฌ๋œ ๋งค๊ฐœ ๋ณ€์ˆ˜๊ฐ’์œผ๋กœ ํ˜„์žฌ ๊ฐ์ฒด์˜ ์†์„ฑ์„ ์„ค์ •ํ•œ๋‹ค.
this๊ฐ€ ์—†๋‹ค๋ฉด ์†์„ฑ์„ ์ง€์—ญ ๋ณ€์ˆ˜๋กœ ํ˜ผ๋™ํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๊ฐ์ฒด์˜ ์†์„ฑ์—๋Š” ๋ฐ˜๋“œ์‹œ this๋ฅผ ๋ถ™์ธ๋‹ค.
์•ž์— this๊ฐ€ ๋ถ™์ธ ๋ณ€์ˆ˜ = ์†์„ฑ
์•ž์— this๊ฐ€ ๋ถ™์€ ํ•จ์ˆ˜ = ๋ฉ”์„œ๋“œ (ํ•จ์ˆ˜๊ฐ€ ๊ฐ์ฒด ์•ˆ์— ๋‚ด์žฅ๋˜์–ด ์žˆ์œผ๋ฉด ๋ฉ”์„œ๋“œ)

๋‚ด์žฅ ๊ฐ์ฒด๋Š” ๋ฏธ๋ฆฌ ์ƒ์„ฑ์ž ํ•จ์ˆ˜๊ฐ€ ์ž‘์„ฑ๋˜์–ด ์žˆ์œผ๋ฏ€๋กœ ์ƒ์„ฑ์ž๋ฅผ ์ž‘์„ฑํ•  ํ•„์š” ์—†์ด new ํ•˜์—ฌ์„œ ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

์˜ˆ์‹œ2)

function Car(model, speed, color){ //Car ์ƒ์„ฑ์ž ์„ ์–ธ
// ์†์„ฑ
this.model=model;
this.speed=speed;
this.color=color;

// ํ•จ์ˆ˜
brake = function(){
this.speed -= 10; // this.speed = this.speed - 10
}

excel = function(){
this.speed += 10; // this.speed = this.speed + 10
}
}
//Car ์ƒ์„ฑ์ž ํ˜ธ์ถœ
mycar = new Car("520d", 60, "red"); //๊ฐ model, speed, color
//์ƒ์„ฑ์ž ์ด์šฉํ•ด์„œ ๊ฐ’ ๋ฐ”๊พผ๋‹ค.
mycar = new Car("520d", 60, "yellow");
document.write("๋ชจ๋ธ: "+mycar.model+" ์†๋„: "+mycar.speed+"<br>")

: During form submission, if a particular entry is unfilled, return false is used to prevent the submission of the form.
 
 

 

2023.01.11 - [1. Revision 2023/Javascript] - [11] 230111 Ch. 8 ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ธฐ์ดˆ(3): ์กฐ๊ฑด๋ฌธ, ๋ฐ˜๋ณต๋ฌธ

if () {
 return;
}
null์„ ๋ฐ˜ํ™˜ (null์„ return)


if () {
 return true;
}
> true์„ ๋ฐ˜ํ™˜ (true์„ return)


if () {
 return false;
}
> false์„ ๋ฐ˜ํ™˜ (false์„ return)
  • return์€ ํ•จ์ˆ˜ ์‹คํ–‰์„ ์ข…๋ฃŒํ•˜๊ณ , ํ•จ์ˆ˜๋ฅผ ๋น ์ ธ๋‚˜์˜จ๋‹ค.
  • break๋Š” ํ˜„์žฌ ๋ฃจํ”„ ์ฆ‰, switch๋‚˜ for, while๋ฌธ ๋“ฑ์„ ์ข…๋ฃŒํ•˜๊ณ  ๋ฃจํ”„์—์„œ ๋น ์ ธ๋‚˜์˜จ๋‹ค.
  • ๋งŒ์•ฝ์— ํ•จ์ˆ˜ ์•ˆ์— ์ž‘์„ฑ๋œ ๋ฃจํ”„ ์•ˆ์—์„œ break๊ฐ€ ์“ฐ์˜€๋‹ค๋ฉด, break๋ฅผ ๊ฐ์‹ธ๊ณ  ์žˆ๋Š” ๋ฃจํ”„๋ฅผ ๋น ์ ธ๋‚˜๊ฐ€๊ณ  ํ•จ์ˆ˜ ๋ฐ–์œผ๋กœ๋Š” ๋‚˜๊ฐ€์ง€ ์•Š๋Š”๋‹ค. return์€ ํ•จ์ˆ˜ ์‹คํ–‰์„ ์ข…๋ฃŒํ•˜๊ณ  ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•œ ๊ณณ์œผ๋กœ ์‹คํ–‰ ํ๋ฆ„์„ ์˜ฎ๊ธด๋‹ค.

์ฐธ๊ณ : https://jihyehwang09.github.io/2019/03/12/js-return-and-break/


728x90
๋ฐ˜์‘ํ˜•
Comments