Created
February 28, 2024 22:44
-
-
Save ryenski/ca621368bb1e5451ce7c11a922a34f0c to your computer and use it in GitHub Desktop.
Javascript Constructors
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
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