-
-
Save tedchoward/45885eebc2136d9098e4397a79cfdd31 to your computer and use it in GitHub Desktop.
Question about best practice with JS objects and internal method calls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Capitalize the name of the constructor function | |
var MessageOfTheDay = function (appName) { | |
this._readHttpCallback = this._readHttpCallback.bind(this); | |
this.appName = appName; | |
if (this.lastMessageText === undefined) { | |
this.lastMessageText = ""; | |
} | |
}; | |
messageOfTheDay.prototype = { | |
sayHello: function () { | |
console.log ("hello"); | |
}, | |
checkForUpdate: function () { | |
var urlTextFile = "http://1999.io/testing/motd/" + this.appName + ".txt"; | |
var motd = this; | |
readHttpFile (urlTextFile, this._readHttpCallback); | |
}, | |
_readHttpCallback: function (s) { | |
if (s !== this.lastMessageText) { | |
console.log('messageOfTheDay.checkForUpdate: s ==', s); | |
this.sayHello(); | |
} | |
} | |
}; | |
// construct a new instance of the 'class' you just defined | |
var messageOfTheDay = new MessageOfTheDay(appName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment