// 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");