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
function Paper() {}; | |
Paper.prototype.beats = function( o ) { | |
if( o.constructor === Rock ) { | |
return true; | |
} else if ( o.constructor === Paper ) { | |
return false; | |
} else if ( o.constructor === Scissors ) { | |
return false; |
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
function Paper() { | |
} | |
Paper.prototype.beats = function( o ) { | |
return o.beatenByPaper(); | |
}; | |
Paper.prototype.beatenByPaper = function() { | |
return false; | |
}; |
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
function stuff() { | |
var start = new Date(); | |
// notice how 'stuff' is in the the call stack | |
debugger; | |
setTimeout(function timeout() { | |
var end = new Date() | |
, diff = end - start; | |
// notice how 'stuff' is NOT in the call stack | |
debugger; | |
console.log( diff + 'ms have passed' ); |
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
var clickCount = 0, link; | |
link = document.getElementById('masochist') | |
link.innerHTML = 'How many times can you click me?'; | |
link.onclick = function(){ | |
clickCount++; | |
link.onclick = function(){ clickCount++; }; | |
start = new Date(); | |
while (new Date() - start < 5000) {} | |
console.log(clickCount); // this will always be 1 |
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
var clickCount = 0, link; | |
link = document.getElementById('masochist') | |
link.innerHTML = 'How many times can you click me?'; | |
link.onclick = function(){ | |
clickCount++; | |
link.onclick = function(){ clickCount++; }; | |
start = new Date(); | |
while (new Date() - start < 5000) {} | |
console.log(clickCount); // this will always be 1 |
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
function Interface(methodNames) { | |
var self = this; | |
methodNames.forEach(function(name) { | |
self[name] = function() { | |
throw new Error('Interface methods should not be called directly. Overwrite with specific implementation details.'); | |
}; | |
}); | |
} | |
Function.prototype.implement = function(_interface, methodHash) { |
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
h1 This is a heading! | |
h2.warning This is a warning | |
p.info this is a paragraph, with an image nested inside, at the end. | |
img(src='http://some.url') | |
<h1>This is a heading!</h1> | |
<h2 class="warning">This is a warning</h2> | |
<p class="info">this is a paragraph, with an image nested inside, at the end.<img src="http://some.url"></p> |
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
// file index.jade | |
html | |
head | |
block head | |
body | |
block content | |
// file view.jade | |
extends index.jade |
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
// tell express where to find our jade templates | |
app.set('views', path.join(__dirname, '../views')); | |
// tell express to use jade to compile view files | |
app.set('view engine', 'jade'); | |
// now we can call response.render(), just like jade.render() | |
app.get('/', function(request, response) { | |
response.render('layouts/index.jade'); | |
}); |
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
// rendering the content of a variable | |
li.tweet | |
img(src= tweet.profile_image_url) | |
h5= tweet.from_user_name | |
p= tweet.text | |
// executing some JS and conditionally render one line or the other | |
- var tweets = link._tweets.length || null; | |
ul.meta |
OlderNewer