COLLECTED BY
Organization:
Internet Archive
Focused crawls are collections of frequently-updated webcrawl data from narrow (as opposed to broad or wide) web crawls, often focused on a single domain or subdomain.
The Wayback Machine - https://web.archive.org/web/20201220220200/https://github.com/lodash/lodash/blob/master/before.js
Permalink
Cannot retrieve contributors at this time
32 lines (31 sloc)
922 Bytes
/**
* Creates a function that invokes `func`, with the `this` binding and arguments
* of the created function, while it's called less than `n` times. Subsequent
* calls to the created function return the result of the last `func` invocation.
*
* @since 3.0.0
* @category Function
* @param {number } n The number of calls at which `func` is no longer invoked.
* @param {Function } func The function to restrict.
* @returns {Function } Returns the new restricted function.
* @example
*
* jQuery(element).on('click', before(5, addContactToList))
* // => Allows adding up to 4 contacts to the list.
*/
function before ( n , func ) {
let result
if ( typeof func !== 'function' ) {
throw new TypeError ( 'Expected a function' )
}
return function ( ...args ) {
if ( -- n > 0 ) {
result = func . apply ( this , args )
}
if ( n <= 1 ) {
func = undefined
}
return result
}
}
export default before
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session.
You signed out in another tab or window. Reload to refresh your session.