- Barajar
ActivarDesactivar
- Alphabetizar
ActivarDesactivar
- Frente Primero
ActivarDesactivar
- Ambos lados
ActivarDesactivar
- Leer
ActivarDesactivar
Leyendo...
Cómo estudiar sus tarjetas
Teclas de Derecha/Izquierda: Navegar entre tarjetas.tecla derechatecla izquierda
Teclas Arriba/Abajo: Colvea la carta entre frente y dorso.tecla abajotecla arriba
Tecla H: Muestra pista (3er lado).tecla h
Tecla N: Lea el texto en voz.tecla n
Boton play
Boton play
30 Cartas en este set
- Frente
- Atrás
3 rules to Write functions
|
Don't Repeat Yourself (DRY)
Do One Thing (DOT) Keep It Simple Stupid (KISS) Less Is More |
Best Practices to write code
|
- Indentation (tabs ?)
- Use Semicolons - Bracket Placement: Right Side - Avoid Name Collisions - Use One var Statement per Function - Use Functional Iterators When Possible |
Tabs or spaces?
|
both have their merits. Tab users say it saves them keystrokes, there are never any hidden whitespace characters, and tabs allow users to set their own indentation display preferences. Space users say that most editors will automatically substitute spaces for tabs and support "soft tabs" that have similar display characteristics to tabs. And you can line up your code better with more fine-grained control of your whitespace.
The important is that you pick one and stick with it |
ASI
|
Automatic semicolon insertion
|
A pure function has no side effects
|
It does not alter existing variables or program state in any way, and always returns the same value given the same inputs.
|
Function definition
|
-Several Ways(Declaration and Expression)
|
Function declaration
|
function foo() {
/* Warning: arguments.callee is deprecated. Use with caution. Used here strictly for illustration. */ return arguments.callee; } |
Function Expression
|
var bar = function () {
return arguments.callee; }; |
Advantage of function expressions
|
- assign functions to variables the same way you would assign values to variables
|
Disadvantage is function expressions
|
create anonymous functions unless you explicitly provide a name(issue to debug the call stack)
|
Named function expressions
|
are like anonymous function expressions in every way, except that they have a name that you can use from inside the function (for recursion).
|
lambda
|
function that is used as data
|
lambdas are commonly used to:
|
- Perform operations on the other arguments passed in
- Attach event handlers for DOM interactions. - Return a function from another function |
Closure
|
A closure is created when a function references data that is contained outside the function scope.
|
If a function is used as an argument or return value, it's a __
|
lambda
|
Immediately Invoked Function Expressions
|
IIFE
|
When use IIFE?
|
This technique is often used to create a new scope to encapsulate modules.
|
.call() method
|
shared by all functions allows you to call any method or function on any object.
someMethod.call(context, argument1, argument2, ...); |
Help us to change the method context of a function
|
call, apply and bind
|
Apply method
|
someMethod.apply(context, someArray);
|
Function.prototype.bind()
|
Method is used to permanently set the value of this inside the target function to the passed in context object.
|
Closures
|
In a nutshell, a closure stores function state, even after the function has returned. To create a closure, simply define a function inside another function and expose it. To expose a function, return it or pass it to another function. The inner function will have access to the variables declared in the outer function. This technique is commonly used to give objects data privacy.
|
Function Polymorphism
|
polymorphism means that something behaves differently based on context, like words that have different meanings based
|
Method dispatch
(for Polymorphism) |
Method dispatch is the mechanism that determines what to do when an object receives a message. JavaScript does this by checking to see if the method exists on the object. If it doesn't, the JavaScript engine checks the prototype object
|
Stateless Functions
|
Pure functions are stateless. This means that they do not use or modify variables, objects, or arrays that were defined outside the function
|
Asynchronous Operations
|
Normally, the JavaScript engine will execute code line by line, in order from top to bottom, following the normal flow of your program (such as function calls, conditional logic, etc.).
|
To Parts of Asynch Operations
|
Asynchronous operations are broken up into two phases: call and response. By definition, it's impossible to know at what point in the program flow you'll be when you receive an asynchronous response. There are a couple of popular ways to manage that uncertainty.
|
Callbacks
|
functions that you pass as arguments to be invoked when the callee has finished its job
|
Promises
|
are objects that allow you to add callback functions to success or failure queues.
|
Deferred
|
the object that controls the promise
|