#Day34
Clean coders videos: http://cleancoders.com/
Morning exercise: https://gist.github.com/mathildathompson/9963766
if your variable is define with "var" it makes it local, otherwise global. TO make obvious that you want a variable to be global, you can add "window." in front of it.
When learning a new language, check scope and pass by value or pass by reference
Javascript uses pass by reference for arrays and objects.
when copying an array, add .slice(0) to your copy of the array to be able to add or remove things from it without affecting the original array.
We can put default value for argument when defining function:
def chicken = function(arg="something){ }; chicken(); This will not return undefined because we defined the default value.
$('.someClass a'); will return all the a in this class
Pseudo selector: $('li:even); selects every even number of li (0,2,4,...)
$('a:lt(3)'); selects the first 3 a. Select by index (lt).
caching: var
Getting attributes: .attr('attributeName', 'attributeValue') Setting attributes:
-
.addClass
-
.removeClass
-
.toggleClass
-
.hasClass => return true /false
-
.is => return true/false
-
.before
-
.after.wrap
-
.append
-
.prepend
Mouse(click, mousedown, mouseup, mousemove)
.preventDefault prevent the default action from happening.
$('a').click(function(event){
event.preventDefault();
});
Javascript event keycode: http://asquare.net/javascript/tests/KeyCode.html
.bind() is the old .on()
HOMEWORK:
https://gist.github.com/wofockham/94e05530e180abbda5ed
User underscore to check if letter entered in the array of the original word