// this is from MS Press book NodeJS for .Net developers // functions as function arguments /*The special thing about JavaScript and passing functions to functions (such as function A as an argument to function B) is that function B doesn't actually use that function per se or anything that it does. Instead, it wires that function as a callback. The function createServer is not taking any arguments other than a callback function. Whatever object is returned from the createServer function you called must have a listen function as one of its properties that activates the underlying server code. */ http.creatServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1234, '127.0.0.1'); //The code could be written as follows for clarity (less performant): var server = http.creatServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }); server.listen(1234, '127.0.0.1'); // object oriented Javascript function Person(){ this.lastName = ""; this.firstName = ""; } function Player() { this.prototype = Person: this.sport = "Football"; this.displayName = function() { return(this.lastName + ',' + this.firstName); } } var oPlayer = new Player(); oPlayer.firstName = "Walter"; oPlayer.lastName = "Playton"; alert(oPlayer.displayName()); var oPlayer = new Player(); oPlayer.firstNAme = "Babe"; oPlayer.lastName = "Ruth"; oPlayer.position = "Pitcher"; this.displayName = function()( { this.lastName + ',' + this.firstName + ":" + this.position; } alert(oPlayer.displayName()); function Question(oQuestion, oAllAnswers, oCorrectAnswer) { this.questionText = oQuestion; this.answerList = oAllAnswers; this.correctAnswer = oCorrectAnswer; } // Which of these players was on a baseball team? // Walter Payton // Babe Ruth // Tiger Woods