Skip to content

Instantly share code, notes, and snippets.

View natevenn's full-sized avatar

Nate Venn natevenn

  • Prague, Czechia
View GitHub Profile
built in effects are:
.show() - show element
.hide() - hide element
.fadein()
.fadeout()
.slidein()
.slideout()
.toggle()
these methods also allow for time duration for effects. time is in milliseconds
jQuery can bind items or elements to event handlers and when triggered invokes code to be run, such as on click.
jQuery uses shorthand methods for these events such as .click(), .mouseover(), .blur()
under the hood these methods use the .on() method
the .off() method unbinds the event to that item.
namespaces with .on() allow you to target a specific event - example being $('li').on('click.logging', function(){ some code })
logging is the namespace
.on() also allows multiple events to be triggered at once
Traversal - is moving thru the html elements
- make a selection and move in reference to that selection. Then manipulate elements to that selection or related to
traversal methods:
use .filter() to select elements with curtain criteria
use .sibling(), .parent(), .next(), .find() to select an element relative to initial selection
use .add() to add to exisiting selection and pass it more html
use .end() to get back to initial selection
use $(document).ready() to ensure the page is ready to be manipulated.
.ready() can take arg such a functions
$('some element') creates a js object that you can do something with or manipulate in some way
note that you must create a js object of a dom element to call jquery methods on it
the methods you can call on these objects are either getters or setters
jQuery is a library built on top of JS
variables are the way we store values and they can be text, numbers, data, and code
functions are how we wrap our code or pieces of functionality
- function expressions are variables that point to a function
- function declarations are named functions
everything in JS is an obj expect - null, strings, booleans, numbers, and undefined
Objects and inheritance
A JS property is an object with a key, value pair with maps from string to values.
three types of properties are named data properties, named accessor properties, and internal properties
Use 'this' in methods to refer to current object
use the dot operator to get the properites value (this.name) only fixed property keys
the 'delete' operator removes a property
the 'bracket' operator works with property expressions and returns the value
To declare a variable use var something = or var something;
Variables in JavaScript are lexically scoped, if nested then it is available in all those scopes
a var inside a scope takes precedence over the var with same name outside of scope, also called blocked scope
a workaround of blocked scopes is to introduce a new scope in a then block. Also called an IIFE or immediately invoked function expression
An IIFE enables you to attach private data to a function and therefore dont have to declare a global variable
A globally scoped variable is avaiable to entire program
two disadvantages of gloabal var are the side effects - they are less robust, behave less predictably, and are less reusable
and all JS on a webpage share the same global variables so naming can clash with other var.
Function declaration are functions that have value. can return the value of a function by calling return
otherwise undefined is returned.
3 roles of functions are nonmethod functions - where you call a function directly, Constructor - like a object factory, methods
difference between parameter and arg is that a parameter defines a function and an argument invokes a function
functions can be expressed as anonymous or named
Hoisting is moving functions to the beginning of scope. function declarations are completely hoisted but varable declarations are just partially hoisted
JS is dynamic in the sense that it can remove and add objects and be created with out having a class.
JS is dynamically typed so it can hold values of any type
JS is functional and OO
JS fails silently and initially couldnt throw exceptions
JS is always deployed as source code and compiled by a JS engine. The two technics use are compressiong and minification
JS is essential on part of the web platform but can be used on the server side too.
JS has quirks like all numbers are treated as floats and arrays are not indexed sequences but maps of numbers to elements, which can leave holes where a index could have no element
JS elegant parts are its first class functions, closures, Prototypes, object literals, and array litters
JS was influenced by JAVA, Perl, AWK, hypertalk, self, and Schema
WeWorkRemotely, AuthenticJobs, StackOverflow Careers, Github Jobs, TopRubyJobs