addHandler.js

function addHandler(target, eventType, handler){ //overwrite the existing function if (target.addEventListener){ //DOM2 Events addHandler = function(target, eventType, handler){ target.addEventListener(eventType, handler, false); }; } else { //IE addHandler = function(target, eventType, handler){ target.attachEvent("on" + eventType, handler); }; } //call the new function addHandler(target, eventType, handler); } function removeHandler(target, eventType, handler){ //overwrite the existing function if (target.removeEventListener){ //DOM2 Events removeHandler = function(target, eventType, handler){ target.addEventListener(eventType, handler, false); }; } else { //IE removeHandler = function(target, eventType, handler){ target.detachEvent("on" + eventType, handler); }; } //call the new function removeHandler(target, eventType, handler); }
The first way to eliminate work repetition in functions is through lazy loading. Lazy loading means that no work is done until the information is necessary.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.