1/** 2 * Mark a JavaScript function as deprecated 3 * 4 * This will print a warning to the JavaScript console (if available) in 5 * Firebug and Chrome and a stack trace (if available) to easily locate the 6 * problematic function call. 7 * 8 * @param msg optional message to print 9 */ 10function DEPRECATED(msg){ 11 if(!window.console) return; 12 if(!msg) msg = ''; 13 14 var func; 15 if(arguments.callee) func = arguments.callee.caller.name; 16 if(func) func = ' '+func+'()'; 17 var line = 'DEPRECATED function call'+func+'. '+msg; 18 19 if(console.warn){ 20 console.warn(line); 21 }else{ 22 console.log(line); 23 } 24 25 if(console.trace) console.trace(); 26} 27 28/** 29 * Construct a wrapper function for deprecated function names 30 * 31 * This function returns a wrapper function which just calls DEPRECATED 32 * and the new function. 33 * 34 * @param func The new function 35 * @param context Optional; The context (`this`) of the call 36 */ 37function DEPRECATED_WRAP(func, context) { 38 return function () { 39 DEPRECATED(); 40 return func.apply(context || this, arguments); 41 }; 42} 43