Copy <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
let i = "내이름은 웹쓰이며, 직업은 웹 퍼블리셔입니다."
let s = "내이름은 도하은이며, 내일 자기소개 할겁니다."
document.write(i,"<br>",s);
document.write("<br><br>");
//매개변수가 있는 함수로 출력
function fun1(name,job){
document.write("내이름은"+name+"이며, 직업은"+job+"입니다.<br>");
}
fun1("웹쓰","웹퍼블리셔");
fun1("도하은","웹퍼블리셔");
document.write("<br><br>");
//변수를 선언하고 함수로 출력
function fun2(name,job){
document.write("내이름은"+name+"이며, 직업은"+job+"입니다.<br>");
}
let youName1="웹쓰";
let youJob1="웹퍼블리셔";
let youName2="도하은";
let youJob2="웹퍼블리셔";
fun2(youName1,youJob1)
fun2(youName2,youJob2)
document.write("<br><br>");
//객체를 선언을 함수로 출력
function fun3(name,job){
document.write("내이름은 "+name+"이며, 내직업은"+job+"입니다.<br>");
}
const you = [
{
name : "웹쓰",
job : "웹퍼블리셔"
},
{
name : "웹스토리보이",
job: " 프론트앤드 개발자"
}
];
fun3(you[0].name, you[0].job);
fun3(you[1].name, you[1].job);
document.write("<br><br>");
//객체+메서드
const you2 = {
name1: "웹쓰",
job1: "웹퍼블리셔",
name2: "웹스토리보이",
job2: "프론트앤드 개발자",
study1 : function(){
document.write("내이름은 "+this.name1+"이며, 내직업은"+this.job1+"입니다.<br>");
},
study2 : function(){
document.write("내이름은 "+this.name2+"이며, 내직업은"+this.job2+"입니다.<br>");
}
}
you2.study1();
you2.study2();
document.write("<br><br>");
//객체 생성자 함수(함수+인스턴스 객체(매개변수))
function You3(name,job){
this.name = name;
this.job = job;
this.study = function(){
document.write("내이름은 "+this.name+"이며, 내직업은"+this.job+"입니다.<br>");
}
}
let char1 = new You3("웹쓰","웹퍼블리셔");
let char2 = new You3("웹스토리보이","프론트앤드 개발자");
char1.study();
char2.study();
document.write("<br><br>");
//프로토타입 메서드
function You4(name,job){
this.name = name;
this.job = job;
}
You4.prototype.study = function(){
document.write("내이름은 "+this.name+"이며, 내직업은"+this.job+"입니다.<br>");
}
let char3 = new You4("웹쓰","웹퍼블리셔");
let char4 = new You4("웹스토리보이","프론트앤드 개발자");
char3.study();
char4.study();
document.write("<br><br>");
//객체 리터럴
function You5(name,job){
this.name = name;
this.job = job;
}
You5.prototype = {
study1 : function(){
document.write("내이름은 "+this.name+"이며, 내직업은"+this.job+"입니다.<br>");
},
study2 : function(){
document.write("내이름은 "+this.name+"이며, 내직업은"+this.job+"입니다.<br>");
}
}
let char5 = new You5("웹쓰","웹퍼블리셔");
let char6 = new You5("웹스토리보이","프론트앤드 개발자");
char5.study();
char6.study();
document.write("<br><br>");
</script>
</head>
<body>
</body>
</html>