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
// 4: given the following code, and assuming that each defined object has a | |
// 'destroy' method, how would you destroy all of the objects contained in the | |
// myObjects object? | |
var myObjects = { | |
thinger : new myApp.Thinger(), | |
gizmo : new myApp.Gizmo(), | |
widget : new myApp.Widget() | |
}; |
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
// 5: given the following array, create an array that contains the contents of | |
// each array item repeated three times, with a space between each item. so, | |
// for example, if an array item is 'foo' then the new array should contain an | |
// array item 'foo foo foo'. (you can assume the library of your choice is | |
// available) | |
var myArray = [ 'foo', 'bar', 'baz' ]; |
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
// 6: how could you improve the following code? | |
$(document).ready(function() { | |
$('.foo #bar').css('color', 'red'); | |
$('.foo #bar').css('border', '1px solid blue'); | |
$('.foo #bar').text('new text!'); | |
$('.foo #bar').click(function() { | |
$(this).attr('title', 'new title'); | |
$(this).width('100px'); | |
}); | |
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
// 7: what issues do you see with the following code? how would you fix it? | |
(function() { | |
var foo; | |
dojo.xhrGet({ | |
url : 'foo.php', | |
load : function(resp) { | |
foo = resp.foo; | |
} | |
}); |
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
// 8: how could you rewrite the following code to make it shorter? | |
(function(d, $){ | |
$('li.foo a').attr('title', 'i am foo'); | |
$('li.bar a').attr('title', 'i am bar'); | |
$('li.baz a').attr('title', 'i am baz'); | |
$('li.bop a').attr('title', 'i am bop'); | |
})(dojo, dojo.query); |
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
// 9: how would you improve the following code? | |
for (i = 0; i <= 100; i++) { | |
$('#thinger').append('<p><span class="thinger">i am thinger ' + i + '</span></p>'); | |
$('#gizmo').append('<p><span class="gizmo">i am gizmo ' + i + '</span></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
// 11: given the following data structure, write code that returns an array | |
// containing the name of each item, followed by a comma-separated list of | |
// the item's extras, if it has any. e.g. | |
// | |
// [ "Salad (Chicken, Steak, Shrimp)", ... ] | |
// | |
// (you can assume the library of your choice is available) | |
var menuItems = [ | |
{ | |
id : 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
// BONUS: write code such that the following alerts "Hello World" | |
say('Hello')('World'); |
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
// 1: how could you rewrite the following to make it shorter? | |
if (foo) { | |
bar.doSomething(el); | |
} else { | |
bar.doSomethingElse(el); | |
} |
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
// override the bar prop for foo w/o affecting bim | |
foo.bar = 'new value'; | |
// change the bar prop for both foo and bim | |
// (*if* it hasn't been overridden locally!) | |
Thinger.prototype.bar = 'another new value'; | |
// we could delete foo.bar now and it would get | |
// the prototype value instead | |
// delete foo.bar; |