Let's start with a simple concept.
1 + 1
=> 2
Adding parens clarifies order of operations.
var post = $('.wall-post-copy').first(); | |
if (post.children().first().attr('target') == "_blank") { | |
post.children().first().css('display', 'none') } |
// Get proper container height | |
function getContainerHeight(){ | |
var myHeight = $('#my-header').outerHeight(), | |
var yourHeight = $('#deal-details').height(), | |
containerHeight = ( myHeight > yourHeight ? myHeight : yourHeight ); | |
return containerHeight; | |
} |
= content_for :meta do | |
meta content=FACEBOOK['client_id'] property="fb:app_id" / | |
meta content=@user.url property="og:url" / | |
meta content=@user.short_title property="og:title" / | |
meta content=@user_sharing.facebook_data[:description] property="og:description" / | |
meta content=@user_sharing.facebook_data[:photo_url] property="og:image" / | |
meta content="summary" name="twitter:card" / | |
meta content="@lettucebooks" name="twitter:site" | |
meta content=@user.url name="twitter:url" | |
meta content=@user.short_title name="twitter:title" |
// Arguments look like array's but are not. But you can add array functionality with prototype. | |
function Max(x,y,z) { | |
var args = Array.prototype.slice.call(arguments); | |
return args; | |
} |
// Use index of to check contents of array. | |
// A function that takes a character (i.e. a string of length 1) and returns true if it is a vowel, false otherwise. | |
function isVowel(letter) { | |
vowels = ['a','e','i','o','u']; | |
var result = vowels.indexOf(letter) | |
if (result >= 0) { | |
return true; | |
} | |
else { |
function sum ( args ) { | |
var array, sum = 0; // Set vars | |
// Conditional to type check what the arguments are | |
if ( typeof args == 'number' ) { // If not an array, then convert it to one. | |
array = Array.prototype.slice.call(arguments, 0); // Gotcha, using the key word 'arguments', not the 'args' word. 'arguments' is a special word in javascript that looks like an array, but is not. | |
} else { | |
array = args; | |
} | |
for ( i in array ) { // I assume recursion could be used here if I knew how recursion worked. |
When I told people I was confused about callbacks I often heard that callbacks were just functions. So I couldn't figure out what my hurdle was to grasping them. But I just had an AH-HA! moment after getting a better grasp on some basic syntax.
JavaScript functions use ()
for two different reasons. Let me recap so that we're on the same page;
1st | Declaration
Getting comfortable with the shorthand conditional syntax. If you put the conditional on one line, the {}
are not needed.
Even when having multiple conditionals.
return
will terminate the function and spit out as it sees. No need to assign the argument to a variable.