Skip to content

@ziyan-junaideen /safe_callback.coffee
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Making callback functions safe - I mean not fail catastrophically because not providing a function or array of functions
class window.SafeCallback
@arrayCallback: ( callback ) ->
if typeof callback == 'function'
console.log "SafeCallback: expected array, found function..."
return [ callback ]
if callback instanceof Array
console.log "SafeCallback: filtering functions from array..."
result = []
for item in callback
result.push item if typeof item == 'function'
return result
console.log "SafeCallback: error with callback..."
return () ->
@callback: ( callback ) ->
return callback if typeof callback == 'function'
return () ->
// Generated by CoffeeScript 1.6.3
(function() {
window.SafeCallback = (function() {
function SafeCallback() {}
SafeCallback.arrayCallback = function(callback) {
var item, result, _i, _len;
if (typeof callback === 'function') {
console.log("SafeCallback: expected array, found function...");
return [callback];
}
if (callback instanceof Array) {
console.log("SafeCallback: filtering functions from array...");
result = [];
for (_i = 0, _len = callback.length; _i < _len; _i++) {
item = callback[_i];
if (typeof item === 'function') {
result.push(item);
}
}
return result;
}
console.log("SafeCallback: error with callback...");
return function() {};
};
SafeCallback.callback = function(callback) {
if (typeof callback === 'function') {
return callback;
}
return function() {};
};
return SafeCallback;
})();
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.