티스토리 뷰
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 |