Skip to content

Instantly share code, notes, and snippets.

@postpostscript
postpostscript / object-map-filter.coffee
Created July 10, 2015 22:39
Object mapping and filtering
MapObj = (obj, mapFn) ->
if obj.length && obj.join
return obj.map(mapFn)
result = {}
result[key] = mapFn(val, key) for key, val of obj
result
FilterObj = (obj, filterFn) ->
if obj.length && obj.join
return obj.filter(filterFn)
@postpostscript
postpostscript / event-framework.js
Created June 21, 2015 22:31
Simple event triggering/handling framework
function hasProperty(obj, prop) {
return obj[prop] !== undefined;
};
Array.prototype.callFunction = function(target, key) {
var args = [].splice.call(arguments, 0).slice(2);
this.forEach(function(elem) {
try {
if (hasProperty(elem, key) && typeof elem[key] == 'function') {