Functions Flashcards

1
Q

_.bind(function, object, *arguments)

A

Bind a function to an object, meaning that whenever the function is called, the value of this will be the object. Optionally, pass arguments to the function to pre-fill them, also known as partial application.

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

_.bindAll(object, *methodNames)

A

Binds a number of methods on the object, specified by methodNames, to be run in the context of that object whenever they are invoked.

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

_.partial(function, *arguments)

A

Partially apply a function by filling in any number of its arguments, without changing its dynamic this value. A close cousin of bind. You may pass _ in your list of arguments to specify an argument that should not be pre-filled, but left open to supply at call-time.

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

_.memoize(function, [hashFunction])

A

Memoizes a given function by caching the computed result. Useful for speeding up slow-running computations. If passed an optional hashFunction, it will be used to compute the hash key for storing the result, based on the arguments to the original function. The default hashFunction just uses the first argument to the memoized function as the key. The cache of memoized values is available as the cache property on the returned function.

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

_.delay(function, wait, *arguments)

A

Much like setTimeout, invokes function after wait milliseconds. If you pass the optional arguments, they will be forwarded on to the function when it is invoked.

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

_.defer(function, *arguments)

A

Defers invoking the function until the current call stack has cleared, similar to using setTimeout with a delay of 0. Useful for performing expensive computations or HTML rendering in chunks without blocking the UI thread from updating. If you pass the optional arguments, they will be forwarded on to the function when it is invoked.

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

_.throttle(function, wait, [options])

A

Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly, will only actually call the original function at most once per every wait milliseconds. Useful for rate-limiting events that occur faster than you can keep up with. If you’d like to disable the leading-edge call, pass {leading: false}, and if you’d like to disable the execution on the trailing-edge, pass {trailing: false}.

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

_.debounce(function, wait, [immediate])

A

Creates and returns a new debounced version of the passed function which will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing behavior that should only happen after the input has stopped arriving. Pass true for the immediate argument to cause debounce to trigger the function on the leading instead of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double-clicks on a “submit” button from firing a second time.

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

_.once(function)

A

Creates a version of the function that can only be called one time. Repeated calls to the modified function will have no effect, returning the value from the original call. Useful for initialization functions, instead of having to set a boolean flag and then check it later.

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

_.after(count, function)

A

Creates a version of the function that will only be run after first being called count times. Useful for grouping asynchronous responses, where you want to be sure that all the async calls have finished, before proceeding.

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

_.before(count, function)

A

Creates a version of the function that can be called no more than count times. The result of the last function call is memoized and returned when count has been reached.

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

_.wrap(function, wrapper)

A

Wraps the first function inside of the wrapper function, passing it as the first argument. This allows the wrapper to execute code before and after the function runs, adjust the arguments, and execute it conditionally.

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

_.negate(predicate)

A

Returns a new negated version of the predicate function.

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

_.compose(*functions)

A

Returns the composition of a list of functions, where each function consumes the return value of the function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).

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

Bind a function to an object, meaning that whenever the function is called, the value of this will be the object. Optionally, pass arguments to the function to pre-fill them, also known as partial application.

A

_.bind(function, object, *arguments)

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

Binds a number of methods on the object, specified by methodNames, to be run in the context of that object whenever they are invoked.

A

_.bindAll(object, *methodNames)

17
Q

Partially apply a function by filling in any number of its arguments, without changing its dynamic this value. A close cousin of bind. You may pass _ in your list of arguments to specify an argument that should not be pre-filled, but left open to supply at call-time.

A

_.partial(function, *arguments)

18
Q

Memoizes a given function by caching the computed result. Useful for speeding up slow-running computations. If passed an optional hashFunction, it will be used to compute the hash key for storing the result, based on the arguments to the original function. The default hashFunction just uses the first argument to the memoized function as the key. The cache of memoized values is available as the cache property on the returned function.

A

_.memoize(function, [hashFunction])

19
Q

Much like setTimeout, invokes function after wait milliseconds. If you pass the optional arguments, they will be forwarded on to the function when it is invoked.

A

_.delay(function, wait, *arguments)

20
Q

Defers invoking the function until the current call stack has cleared, similar to using setTimeout with a delay of 0. Useful for performing expensive computations or HTML rendering in chunks without blocking the UI thread from updating. If you pass the optional arguments, they will be forwarded on to the function when it is invoked.

A

_.defer(function, *arguments)

21
Q

Creates and returns a new, throttled version of the passed function, that, when invoked repeatedly, will only actually call the original function at most once per every wait milliseconds. Useful for rate-limiting events that occur faster than you can keep up with. If you’d like to disable the leading-edge call, pass {leading: false}, and if you’d like to disable the execution on the trailing-edge, pass {trailing: false}.

A

_.throttle(function, wait, [options])

22
Q

Creates and returns a new debounced version of the passed function which will postpone its execution until after wait milliseconds have elapsed since the last time it was invoked. Useful for implementing behavior that should only happen after the input has stopped arriving. Pass true for the immediate argument to cause debounce to trigger the function on the leading instead of the trailing edge of the wait interval. Useful in circumstances like preventing accidental double-clicks on a “submit” button from firing a second time.

A

_.debounce(function, wait, [immediate])

23
Q

Creates a version of the function that can only be called one time. Repeated calls to the modified function will have no effect, returning the value from the original call. Useful for initialization functions, instead of having to set a boolean flag and then check it later.

A

_.once(function)

24
Q

Creates a version of the function that will only be run after first being called count times. Useful for grouping asynchronous responses, where you want to be sure that all the async calls have finished, before proceeding.

A

_.after(count, function)

25
Q

Creates a version of the function that can be called no more than count times. The result of the last function call is memoized and returned when count has been reached.

A

_.before(count, function)

26
Q

Wraps the first function inside of the wrapper function, passing it as the first argument. This allows the wrapper to execute code before and after the function runs, adjust the arguments, and execute it conditionally.

A

_.wrap(function, wrapper)

27
Q

Returns a new negated version of the predicate function.

A

_.negate(predicate)

28
Q

Returns the composition of a list of functions, where each function consumes the return value of the function that follows. In math terms, composing the functions f(), g(), and h() produces f(g(h())).

A

_.compose(*functions)