3 exports.__esModule = true;
4 exports.throttle = exports.bind = undefined;
6 var _guid = require('./guid.js');
9 * Bind (a.k.a proxy or Context). A simple method for changing the context of a function
10 * It also stores a unique id on the function so it can be easily removed from events.
12 * @param {Mixed} context
13 * The object to bind as scope.
15 * @param {Function} fn
16 * The function to be bound to a scope.
18 * @param {number} [uid]
19 * An optional unique ID for the function to be set
22 * The new function that will be bound into the context given
24 var bind = exports.bind = function bind(context, fn, uid) {
25 // Make sure the function has a unique ID
27 fn.guid = (0, _guid.newGUID)();
30 // Create the new function that changes the context
31 var bound = function bound() {
32 return fn.apply(context, arguments);
35 // Allow for the ability to individualize this function
36 // Needed in the case where multiple objects might share the same prototype
37 // IF both items add an event listener with the same function, then you try to remove just one
38 // it will remove both because they both have the same guid.
39 // when using this, you need to use the bind method when you remove the listener as well.
40 // currently used in text tracks
41 bound.guid = uid ? uid + '_' + fn.guid : fn.guid;
47 * Wraps the given function, `fn`, with a new function that only invokes `fn`
48 * at most once per every `wait` milliseconds.
50 * @param {Function} fn
51 * The function to be throttled.
53 * @param {Number} wait
54 * The number of milliseconds by which to throttle.
62 var throttle = exports.throttle = function throttle(fn, wait) {
63 var last = Date.now();
65 var throttled = function throttled() {
68 if (now - last >= wait) {
69 fn.apply(undefined, arguments);