티스토리 뷰


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');


댓글
댓글쓰기 폼