Created
September 16, 2010 23:41
-
-
Save jimbojw/583389 to your computer and use it in GitHub Desktop.
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
// For each of the following code fragments: | |
// a. what does the code do? | |
// b. what did the author intend for it to do? | |
// c. how would you fix it? | |
// 1. list of links | |
var p = document.createElement('p'); | |
for (var i=0; i<10; i++) { | |
var a = document.createElement('a'); | |
a.innerHTML = "link " + i; | |
a.onclick = function() { | |
alert("you clicked link " + i); | |
return false; | |
}; | |
p.appendChild(a); | |
} | |
document.body.appendChild(p); | |
// 2. method callback | |
var bob = { | |
firstname: "Bob", | |
greet: function() { | |
alert("Hi, I'm " + this.firstname); | |
} | |
} | |
window.onload = bob.greet; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Haha, I like the idea of trading to a company.
I'm going to fork the gist and make the changes we talked about: add the browser compatibility note and add the easy first question.