JavaScript
/**
* Add event listener
*/
function addEvent(el, type, fn) {
if (window.addEventListener) {
addEvent = function(el, type, fn) {
el.addEventListener(type, fn, false);
}
} else if (window.attachEvent) {
addEvent = function(el, type, fn) {
var f = function() {
fn.call(el, window.event);
}
el.attachEvent('on' + type, f);
}
}
return addEvent(el,type,fn);
}
Ruby
class BlankSlate
instance_methods.each { |m| undef_method m unless m =~ /^__/ }
end
class Proxy < BlankSlate
def initialize(obj)
@obj = obj
end
def method_missing(sym, *args, &block)
puts "Sending #{sym}(#{args.join(',')}) to obj"
@obj.__send__(sym, *args, &block)
end
end
PHP
class Zend_Memory
{
public static function factory($backend, $backendOptions = array())
{
if (strcasecmp($backend, 'none') == 0) {
return new Zend_Memory_Manager();
}
// because lowercase will fail
$backend = @ucfirst(strtolower($backend));
if (!in_array($backend, Zend_Cache::$availableBackends)) {
throw new Zend_Memory_Exception("Incorrect backend ($backend)");
}
$backendClass = 'Zend_Cache_Backend_' . $backend;
require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
$backendObject = new $backendClass($backendOptions);
return new Zend_Memory_Manager($backendObject);
}
}