Backbone.js Flashcards

1
Q

What is Backbone.js?

A

Backbone.js gives structure to web applications by providing:

  1. models with key-value binding and custom events,
  2. collections with a rich API of enumerable functions,
  3. views with declarative event handling, and
  4. connects it all to your existing API over a RESTful JSON interface.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Events

A

LL OOO ST

listenTo
listenToOnce

once
on
off

stopListening
trigger

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

bind a callback function to an object that’s invoked whenever the event is fired

A

object. on(event, callback)

book. on(“change:title change:author”, doSomething);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

remove previously bound callback function from an object

A

object.off([event], [callback], [context])

// Removes just the `onChange` callback.
object.off("change", onChange);
// Removes all "change" callbacks.
object.off("change");
// Removes the `onChange` callback for all events.
object.off(null, onChange);
// Removes all callbacks for `context` for all events.
object.off(null, null, context);
// Removes all callbacks on `object`.
object.off();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Trigger callbacks for the given event, or space-delimited list of events. Subsequent arguments to trigger will be passed along to the event callbacks.

A

object.trigger(event, [*args])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Just like on, but causes the bound callback to only fire once before being removed. Handy for saying “the next time that X happens, do this”.

A

object.once(event, callback, [context])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Tell an object to listen to a particular event on an other object.

Advantage?

A

object.listenTo(other, event, callback)

Advantage: listenTo allows the object to keep track of the events, and they can be removed all at once later on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Tell an object to stop listening to events.

A

object.stopListening([other], [event], [callback])

Either call stopListening with no arguments to have the object remove all of its registered callbacks … or be more precise by telling it to remove just the events it’s listening to on a specific object, or a specific event, or just a specific callback.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

just like listenTo, but causes the bound callback to only fire once before being removed.

A

object.listenToOnce(other, event, callback)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Built-in Backbone events - master list

A

AA CCDEI 6R 2S

add, all
change, change: [attribute]
destroy, error, invalid

remove, reset, request, route, route (router, route, params), route: [name]

sort, sync

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Backbone events - AA

A

“add” (model, collection, options) — when a model is added to a collection.

“all” — this special event fires for any triggered event, passing the event name as the first argument.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Backbone events - CCDEI

A

“change” (model, options) — when a model’s attributes have changed.

“change:[attribute]” (model, value, options) — when a specific attribute has been updated.

“destroy” (model, collection, options) — when a model is destroyed.

“error” (model, xhr, options) — when a model’s save call fails on the server.

“invalid” (model, error, options) — when a model’s validation fails on the client.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Backbone events - 6R

A

“remove” (model, collection, options) — when a model is removed from a collection.

“reset” (collection, options) — when the collection’s entire contents have been replaced.

“request” (model, xhr, options) — when a model (or collection) has started a request to the server.

“route:[name]” (params) — Fired by the router when a specific route is matched.

“route” (route, params) — Fired by the router when any route has been matched.

“route” (router, route, params) — Fired by history when any route has been matched.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Backbone events - 2S

A

“sort” (collection, options) — when the collection has been re-sorted.

“sync” (model, resp, options) — when a model (or collection) has been successfully synced with the server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

jQuery events - master list

A

CCD 3F H2K L 7M(DELMOOU) 2R 2S U

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

jQuery events - CCD

A

change - when value of a form field is changed

click - when clicked

dbclick - when element is doubleclicked

17
Q

jQuery events - 3F

A

focus - gets focus (selected by mouse click or by “tab-navigating” (pressing tab key to cycle through elements))

focusin - element or any elements inside it (children) get focus

focusout - element or any elements inside it (children) lose focus

18
Q

jQuery events - H2K L

A

hover - specifies 2 functions to run when mouse pointer hovers over selected elements, triggers both mouseenter and mouseleave events

keydown - key pressed, gives scan-code

keypress - guaranteed for char keys only, gives char-code after keydown triggered
- if you press and hold a key, keydown would fire once, but keypress would fire multiple times

keyup - key is released

load - when element is loaded, this method was deprecated in jQuery 1.8

19
Q

jQuery events - 7M(DELMOOU)

A

prefix “mouse” - mousedown
down - left mouse button pressed down over element

enter - mouse pointer over (enters) element

leave - mouse pointer leaves element

move - mouse pointer moves within element

over - mouse pointer over element or any of element’s children (unlike enter), often used with mouseout

out - mouse pointer leaves element or any of element’s children (unlike leave)

up - left mouse button released over element

20
Q

jQuery events - 2R

A

ready - occurs when DOM has been loaded

resize - occurs when browser window changes size

21
Q

jQuery events - 2S U

A

scroll - user scrolls in the specified element

select - text is selected in a text area or text field

unload - user navigates away from page