-
-
Save Rub3nC/01f9af706b07966c2c87 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/tiwusu
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script> | |
| </script> | |
| <script id="jsbin-javascript"> | |
| // Prototypal object | |
| var Person = function (name) { | |
| this.name = name; | |
| }; | |
| Person.prototype.greet = function () { | |
| return this.name; | |
| } | |
| var albert = new Person('Albert Einstein'); | |
| console.log(albert.greet()); | |
| // Anonymous functions as methods | |
| var santa = { | |
| say: function(){ | |
| console.log("Ho, ho, ho!"); | |
| } | |
| }; | |
| santa.say(); | |
| // Anonymous functions as parameters to another function | |
| //function statement | |
| function eventHandler(event){ | |
| event(); | |
| } | |
| eventHandler(function(){ | |
| // Do a lot of event related things | |
| console.log("Event Fired"); | |
| }); | |
| // Closures | |
| function privateTest(){ | |
| var points = 0; | |
| this.getPoints = function(){ | |
| return points; | |
| }; | |
| this.score = function(){ | |
| points++; | |
| } | |
| } | |
| // Private variables | |
| var private = new privateTest(); | |
| private.score(); | |
| console.log( private.points ); | |
| console.log(private.getPoints()); | |
| // Timers and callbacks | |
| /*function delay(message){ | |
| setTimeout(function timerFn(){ | |
| console.log( message ); | |
| }, 10); | |
| } | |
| delay("Hello World!");*/ | |
| // Modules | |
| var superModule = (function(){ | |
| var secret = 'supersecretkey'; | |
| var passcode = 'nuke'; | |
| function getSecret(){ | |
| console.log( secret ); | |
| } | |
| function getPassCode(){ | |
| console.log( passcode ); | |
| } | |
| return { | |
| getSecret: getSecret, | |
| getPassCode: getPassCode | |
| } | |
| })(); | |
| superModule.getSecret(); | |
| superModule.getPassCode(); | |
| var mySet = new Set(); | |
| mySet.add(1); | |
| mySet.add("Howdy"); | |
| mySet.add("Foo"); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">// Prototypal object | |
| var Person = function (name) { | |
| this.name = name; | |
| }; | |
| Person.prototype.greet = function () { | |
| return this.name; | |
| } | |
| var albert = new Person('Albert Einstein'); | |
| console.log(albert.greet()); | |
| // Anonymous functions as methods | |
| var santa = { | |
| say: function(){ | |
| console.log("Ho, ho, ho!"); | |
| } | |
| }; | |
| santa.say(); | |
| // Anonymous functions as parameters to another function | |
| //function statement | |
| function eventHandler(event){ | |
| event(); | |
| } | |
| eventHandler(function(){ | |
| // Do a lot of event related things | |
| console.log("Event Fired"); | |
| }); | |
| // Closures | |
| function privateTest(){ | |
| var points = 0; | |
| this.getPoints = function(){ | |
| return points; | |
| }; | |
| this.score = function(){ | |
| points++; | |
| } | |
| } | |
| // Private variables | |
| var private = new privateTest(); | |
| private.score(); | |
| console.log( private.points ); | |
| console.log(private.getPoints()); | |
| // Timers and callbacks | |
| /*function delay(message){ | |
| setTimeout(function timerFn(){ | |
| console.log( message ); | |
| }, 10); | |
| } | |
| delay("Hello World!");*/ | |
| // Modules | |
| var superModule = (function(){ | |
| var secret = 'supersecretkey'; | |
| var passcode = 'nuke'; | |
| function getSecret(){ | |
| console.log( secret ); | |
| } | |
| function getPassCode(){ | |
| console.log( passcode ); | |
| } | |
| return { | |
| getSecret: getSecret, | |
| getPassCode: getPassCode | |
| } | |
| })(); | |
| superModule.getSecret(); | |
| superModule.getPassCode(); | |
| var mySet = new Set(); | |
| mySet.add(1); | |
| mySet.add("Howdy"); | |
| mySet.add("Foo"); | |
| </script></body> | |
| </html> |
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
| // Prototypal object | |
| var Person = function (name) { | |
| this.name = name; | |
| }; | |
| Person.prototype.greet = function () { | |
| return this.name; | |
| } | |
| var albert = new Person('Albert Einstein'); | |
| console.log(albert.greet()); | |
| // Anonymous functions as methods | |
| var santa = { | |
| say: function(){ | |
| console.log("Ho, ho, ho!"); | |
| } | |
| }; | |
| santa.say(); | |
| // Anonymous functions as parameters to another function | |
| //function statement | |
| function eventHandler(event){ | |
| event(); | |
| } | |
| eventHandler(function(){ | |
| // Do a lot of event related things | |
| console.log("Event Fired"); | |
| }); | |
| // Closures | |
| function privateTest(){ | |
| var points = 0; | |
| this.getPoints = function(){ | |
| return points; | |
| }; | |
| this.score = function(){ | |
| points++; | |
| } | |
| } | |
| // Private variables | |
| var private = new privateTest(); | |
| private.score(); | |
| console.log( private.points ); | |
| console.log(private.getPoints()); | |
| // Timers and callbacks | |
| /*function delay(message){ | |
| setTimeout(function timerFn(){ | |
| console.log( message ); | |
| }, 10); | |
| } | |
| delay("Hello World!");*/ | |
| // Modules | |
| var superModule = (function(){ | |
| var secret = 'supersecretkey'; | |
| var passcode = 'nuke'; | |
| function getSecret(){ | |
| console.log( secret ); | |
| } | |
| function getPassCode(){ | |
| console.log( passcode ); | |
| } | |
| return { | |
| getSecret: getSecret, | |
| getPassCode: getPassCode | |
| } | |
| })(); | |
| superModule.getSecret(); | |
| superModule.getPassCode(); | |
| var mySet = new Set(); | |
| mySet.add(1); | |
| mySet.add("Howdy"); | |
| mySet.add("Foo"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment