Skip to content

Instantly share code, notes, and snippets.

@ryenski
Created February 28, 2024 22:44
Show Gist options
  • Save ryenski/ca621368bb1e5451ce7c11a922a34f0c to your computer and use it in GitHub Desktop.
Save ryenski/ca621368bb1e5451ce7c11a922a34f0c to your computer and use it in GitHub Desktop.
Javascript Constructors
function HelloWorld(str) {
this.str = str;
this.speak = function() {
console.log("hello", this.str);
}
};
var h = new HelloWorld("world");
h.speak();
(new HelloWorld("Jupiter")).speak();
function Howdy() {
this.speak = function (str) {
this.str = str;
console.log("howdy", this.str);
}
}
(new Howdy).speak("Texas");
var Greet = function () {
this.speak = function (str) {
this.str = str;
console.log("hello", this.str);
}
};
(new Greet).speak("how you doing");
var Gutentag = {
speak: function (str) {
this.str = str;
console.log("gutentag", this.str);
}
};
Gutentag.speak("mein freund");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment