티스토리 뷰


1. Simple Object Literal

myApp.notepad  = {};
myApp.notepad.writeable = true;
myApp.notepad.font  = 'helvetica';
myApp.notepad.setFont = function(theFont) {
    myApp.notepad.font = theFont;
}

2. Nested Object Literal

myApp.notepad  = {
    writeable: true,
    font: 'helvetica',
    setFont: function(theFont) {
        this.font = theFont;
    }
}


3, Constructor using Object Literal

myApp.Notepad = function(defaultFont) {
    var  that = {};
    that.writeable = true;
    that.font = defaultFont;
    that.setFont = function(theFont) {
        that.font = theFont;
    }
    return that;
}

4. Simple Constructor for new

myApp.Notepad = function(defaultFont) {
    this.writeable = true;
    this.font = defaultFont;
    this.setFont = function(theFont) {
        this.font = theFont;
    }
}

myApp.notepad1  = new myApp.Notepad('helvetica');


5. Prototype with Constructor for new

myApp.Notepad = function(defaultFont) {
    this.font = defaultFont;
}
myApp.Notepad.prototype.writeable  = true;
myApp.Notepad.prototype.setFont  = function(theFont) {
    this.font = theFont;
}
myApp.notepad1  = new myApp.Notepad('helvetica');


'웹개발 > Javascript' 카테고리의 다른 글

알면 좋은 자바스크립트 간단한 팁,  (0) 2011.01.08
상속 : Inheritance  (0) 2011.01.08
Javascript Switch문을 바꿔서 표현  (0) 2011.01.08
Javascript 재 입문  (0) 2011.01.08
자바스크립트 정규 표현식  (0) 2010.12.23
댓글
D-DAY
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
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
글 보관함