250x250
Notice
Recent Posts
Recent Comments
관리 메뉴

탁월함은 어떻게 나오는가?

[JAVASCRIPT] ClassObject(클래스오브젝트) 본문

[Snow-ball]프로그래밍(컴퓨터)/자바스크립트(JavaScript)

[JAVASCRIPT] ClassObject(클래스오브젝트)

Snow-ball 2021. 2. 1. 22:25
반응형

 

 ClassObject

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
function ClassObject() {
    class Obj {
        // 자바와 자바스크립트 클래스 생성시
        // 생성자를 constructor()로 사용해야 한다.
        constructor() {
            this.name = "test"
            this.major = "electronics"
        }
    }
 
    let obj = new Obj()
 
    console.log("ClassObjectob : " + obj.name)
    console.log("ClassObjectob : " + obj.major)
 
    return (
        <div className="ClassObject">
            <p>
                ClassObject
            </p>
        </div>
    )
}
 
export default ClassObject
cs

출력

 

 

 

 

 

 

 

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
function ClassObject2() {
    class Obj {
        constructor() {
            this.name = "test"
            this.major = "electronics"
        }
 
        getName() {
            return this.name
        }
 
        getMajor() {
            return this.major
        }
 
        setName(name) {
            this.name = name
        }
 
        setMajor(major){
            this.major = major
        }
 
        display() {
            console.log("this.name: " + this.name)
            console.log("this.major: " + this.major)
        }
    }
 
    let obj = new Obj()
 
    console.log("obj.name : " + obj.name)
    console.log("obj.major : " + obj.major)
    console.log("obj.getName : " + obj.getName())
    console.log("obj.getMajor : " + obj.getMajor())
 
    obj.display()
 
    return (
        <div className="ClassObject">
            <p>
                ClassObject2
            </p>
        </div>
    )
}
 
export default ClassObject2
cs

 

 

출력

 

 

 

 

 

 

 

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function ClassObject3() {
    class Obj {
        constructor() {
            this.name = "test"
            this.major = "electronics"
        }
 
        getName() {
            return this.name
        }
 
        getMajor() {
            return this.major
        }
 
        setName(name) {
            this.name = name
        }
 
        setMajor(major){
            this.major = major
        }
 
        display() {
            console.log("this.name: " + this.name)
            console.log("this.major: " + this.major)
        }
 
        static getStaticTest(isTest, number) {
            if(isTest) {
                return 333
            } else {
                // paraseInt(숫자값, 표현하는 진법)
                return parseInt(3.3 * number, 10)
            }
        }
    }
 
    let obj = new Obj()
 
    console.log("ClassObjectob : " + obj.name)
    console.log("ClassObjectob : " + obj.major)
    console.log("ClassObjectob : " + obj.getName())
    console.log("ClassObjectob : " + obj.getMajor())
 
    obj.display()
 
    console.log("Obj.getStaticTest: " + Obj.getStaticTest(true))
    console.log("Obj.getStaticTest: " + Obj.getStaticTest(false100))
 
    return (
        <div className="ClassObject3">
            <p>
                ClassObject3
            </p>
        </div>
    )
}
 
export default ClassObject3
cs

 

출력

 

 

 

 

 

 

 

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function ClassObject4() {
    class Obj {
        constructor(name) {
            this.name = name
            this.major = "electronics"
            Obj.num++
        }
 
        getName() {
            return this.name
        }
        getMajor() {
            return this.major
        }
        setName(name) {
            this.name = name
        }
        setMajor(major) {
            this.major = major
        }
        display() {
            console.log("this.name: " + this.name)
            console.log("this.major: " + this.major)
        }
 
        static getStaticTest(isTest, number) {
            if(isTest) {
                return 333
            } else {
                // parseInt(숫자값, 표현하는 진법)
                return parseInt(3.3 * number, 10)
            }
        }
 
        static getStaticNumber() {
            return Obj.num
        }
    }
 
    Obj.num = 0
 
    let obj = new Obj("test1")
 
    obj.display()
    console.log("ClassObject4 !! : " + Obj.getStaticNumber())
 
    let obj2 = new Obj("test2")
 
    obj2.display()
    console.log("ClassObject4: " + Obj.getStaticNumber())
 
    return (
        <div className="ClassObject4">
            <p>
                Class Object 4
            </p>
        </div>
    )
}
 
export default ClassObject4
cs

출력

 

 

 

 

 

 

 

 

 

베타존 : 네이버쇼핑 스마트스토어

나를 꾸미다 - 인테리어소품 베타존

smartstore.naver.com

 

반응형
Comments