Last active
August 29, 2015 13:57
-
-
Save keyle/9755741 to your computer and use it in GitHub Desktop.
object oriented javascript a la typescript
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
| var App = (function () { | |
| function App() { | |
| console.log("App constructor"); | |
| } | |
| App.prototype.init = function () { // poluting the prototype => instance method | |
| console.log("app.init() is instance init \n" + this); | |
| }; | |
| App.init = function () { // static method | |
| console.log("App.init() is static init \n" + this); | |
| }; | |
| return App; | |
| })(); | |
| var app; | |
| window.onload = function () { | |
| console.log("--- static init: ---"); | |
| App.init(); | |
| console.log("\n--- instance init: ---"); | |
| app = new App(); | |
| app.init(); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment