Skip to content

Instantly share code, notes, and snippets.

@charliegerard
Last active August 29, 2015 13:58
Show Gist options
  • Save charliegerard/9964583 to your computer and use it in GitHub Desktop.
Save charliegerard/9964583 to your computer and use it in GitHub Desktop.

#Day34

Clean coders videos: http://cleancoders.com/

Morning exercise: https://gist.github.com/mathildathompson/9963766


####Review on Javascript:

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 $p = $('#container p'); saves the selection into a variable so we dont have to repeat ourselves.

Getting attributes: .attr('attributeName', 'attributeValue') Setting attributes:

  • .addClass

  • .removeClass

  • .toggleClass

  • .hasClass => return true /false

  • .is => return true/false

  • .before

  • .after.wrap

  • .append

  • .prepend


Events:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment