s16_class.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class</title>
</head>
<body>
<script type="text/javascript">
class Person{
//클레스 필드
name = 'Smith';
//메서드
getName = function(){
return this.name;
};
}
//객체 생성
const me = new Person();
document.write(me);
document.write('<br>');
document.write(me.name);
document.write('<br>');
document.write(me.getName());
</script>
</body>
</html>

s17_class.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class</title>
</head>
<body>
<script type="text/javascript">
//클래스 정의
class Person{
//생성자
constructor(name){
//인스턴스 프로퍼티
this.name = name;
}
//메서드
sayHi(){ //function 키워드 생략한 단순형태
document.write('Hi my name is '+this.name);
}
//정적 메서드
static sayHello(){
document.write('Hello!!');
}
}
//객체 생성
const me = new Person('Annie');
//속성 호출
document.write(me.name);
document.write('<br>');
//메서드 호출
me.sayHi();
document.write('<br>');
//정적 메서드 호출(클래스명을 붙여야됨)
Person.sayHello();//Person은 클래스명.me는 객체명이기 때문에 호출안됨
</script>
</body>
</html>

s18_class.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class</title>
</head>
<body>
<script type="text/javascript">
//부모 클래스 정의
class Animal{
//생성자
constructor(age,weight){
this.age = age;
this.weight = weight;
}
//메서드
eat(){
return "eat";
}
move(){
return "move";
}
}
//자식 클래스 정의(부모 클래스를 자식 클래스에 상속)
class Bird extends Animal{
fly(){
return 'fly';
}
}
//자식 클래스 객체 생성
const bird = new Bird(1,5);
document.write(bird.age+'<br>');
document.write(bird.weight+'<br>');
document.write(bird.eat()+'<br>');
document.write(bird.move()+'<br>');
document.write(bird.fly()+'<br>');
</script>
</body>
</html>

'쌍용교육(JAVA) > JavaScript' 카테고리의 다른 글
쌍용교육 -JavaScript수업 39일차 JSRegular (0) | 2024.04.15 |
---|---|
쌍용교육 -JavaScript수업 38일차 exception (0) | 2024.04.15 |
쌍용교육 -JavaScript수업 38~39일차 JSEvent(3) (0) | 2024.04.15 |
쌍용교육 -JavaScript수업 37~38일차 JSEvent(2) (0) | 2024.04.15 |
쌍용교육 -JavaScript수업 37일차 JSEvent(1) (0) | 2024.04.15 |
s16_class.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class</title>
</head>
<body>
<script type="text/javascript">
class Person{
//클레스 필드
name = 'Smith';
//메서드
getName = function(){
return this.name;
};
}
//객체 생성
const me = new Person();
document.write(me);
document.write('<br>');
document.write(me.name);
document.write('<br>');
document.write(me.getName());
</script>
</body>
</html>

s17_class.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class</title>
</head>
<body>
<script type="text/javascript">
//클래스 정의
class Person{
//생성자
constructor(name){
//인스턴스 프로퍼티
this.name = name;
}
//메서드
sayHi(){ //function 키워드 생략한 단순형태
document.write('Hi my name is '+this.name);
}
//정적 메서드
static sayHello(){
document.write('Hello!!');
}
}
//객체 생성
const me = new Person('Annie');
//속성 호출
document.write(me.name);
document.write('<br>');
//메서드 호출
me.sayHi();
document.write('<br>');
//정적 메서드 호출(클래스명을 붙여야됨)
Person.sayHello();//Person은 클래스명.me는 객체명이기 때문에 호출안됨
</script>
</body>
</html>

s18_class.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>class</title>
</head>
<body>
<script type="text/javascript">
//부모 클래스 정의
class Animal{
//생성자
constructor(age,weight){
this.age = age;
this.weight = weight;
}
//메서드
eat(){
return "eat";
}
move(){
return "move";
}
}
//자식 클래스 정의(부모 클래스를 자식 클래스에 상속)
class Bird extends Animal{
fly(){
return 'fly';
}
}
//자식 클래스 객체 생성
const bird = new Bird(1,5);
document.write(bird.age+'<br>');
document.write(bird.weight+'<br>');
document.write(bird.eat()+'<br>');
document.write(bird.move()+'<br>');
document.write(bird.fly()+'<br>');
</script>
</body>
</html>

'쌍용교육(JAVA) > JavaScript' 카테고리의 다른 글
쌍용교육 -JavaScript수업 39일차 JSRegular (0) | 2024.04.15 |
---|---|
쌍용교육 -JavaScript수업 38일차 exception (0) | 2024.04.15 |
쌍용교육 -JavaScript수업 38~39일차 JSEvent(3) (0) | 2024.04.15 |
쌍용교육 -JavaScript수업 37~38일차 JSEvent(2) (0) | 2024.04.15 |
쌍용교육 -JavaScript수업 37일차 JSEvent(1) (0) | 2024.04.15 |