Skip to content

Instantly share code, notes, and snippets.

@tedchoward
Forked from scripting/example.js
Last active July 12, 2016 15:32
Show Gist options
  • Save tedchoward/45885eebc2136d9098e4397a79cfdd31 to your computer and use it in GitHub Desktop.
Save tedchoward/45885eebc2136d9098e4397a79cfdd31 to your computer and use it in GitHub Desktop.
Question about best practice with JS objects and internal method calls
// 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