Last active
August 29, 2015 14:07
-
-
Save poorcoder/7eecc67088475fa4447d to your computer and use it in GitHub Desktop.
Pete Hodgson talks about how we can expand our programming minds by using JavaScript in unusual and experimental ways in his presentation from Forward JS. http://www.youtube.com/watch?v=n9qzwI4Krmo
This file contains 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
/* | |
* Pete Hodgson talks about how we can expand our programming minds by | |
* using JavaScript in unusual and experimental ways in his presentation | |
* from Forward JS. | |
* http://www.youtube.com/watch?v=n9qzwI4Krmo | |
*/ | |
cakes = ["coffee", "cheese", "bundt", "angel"]; | |
function Person() { | |
this.cakesEaten = 0; | |
} | |
Person.prototype.eatCake = function() { | |
this.cakesEaten += 1; | |
} | |
Person.prototype.stillHungry = function() { | |
return this.cakesEaten < 3; | |
} | |
console.log('Version 1'); | |
var george = new Person(); | |
cakes.forEach(george.eatCake); | |
console.log('Hungry : ', george.stillHungry()); | |
console.log('Eaten Cakes : ', george.cakesEaten); | |
/* -------------------------------------------- */ | |
function createPerson() { | |
var cakesEaten = 0; | |
return { | |
eatCake : function() { | |
cakesEaten += 1; | |
}, | |
stillHungry : function() { | |
return cakesEaten < 3; | |
}, | |
eatenCakes : function() { | |
return cakesEaten; | |
} | |
}; | |
} | |
console.log('Version 2'); | |
var john = createPerson(); | |
cakes.forEach(john.eatCake); | |
console.log('Hungry : ', john.stillHungry()); | |
console.log('Eaten Cakes : ', john.eatenCakes()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment