Last active
February 2, 2016 11:57
-
-
Save mrWinston/348e507891edcb51399a to your computer and use it in GitHub Desktop.
Simple Javascript OOP #javascript #nodejs #oop #object
This file contains hidden or 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
| /* This program is free software. It comes without any warranty, to | |
| * the extent permitted by applicable law. You can redistribute it | |
| * and/or modify it under the terms of the Do What The Fuck You Want | |
| * To Public License, Version 2, as published by Sam Hocevar. See | |
| * http://www.wtfpl.net/ for more details. | |
| */ | |
| // import Object | |
| var object = require("./object.js"); | |
| //init object | |
| var o = new object(); | |
| o.init(); | |
| o.hello("hi!"); |
This file contains hidden or 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
| /* This program is free software. It comes without any warranty, to | |
| * the extent permitted by applicable law. You can redistribute it | |
| * and/or modify it under the terms of the Do What The Fuck You Want | |
| * To Public License, Version 2, as published by Sam Hocevar. See | |
| * http://www.wtfpl.net/ for more details. | |
| */ | |
| /* | |
| Constructor | |
| */ | |
| function Object(){ | |
| return this; | |
| } | |
| /* | |
| Method 1: Logs stuff | |
| */ | |
| Object.prototype.hello = function(str){ | |
| console.log(str); | |
| }; | |
| /* | |
| Method 2: Print stuff | |
| */ | |
| Object.prototype.init = function(){ | |
| console.log("initialized"); | |
| }; | |
| /* | |
| Needed for some reasons... | |
| */ | |
| module.exports = Object |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment