compatibility.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. */
  10. function DEPRECATED(msg){
  11. if(!window.console) return;
  12. if(!msg) msg = '';
  13. var func;
  14. if(arguments.callee) func = arguments.callee.caller.name;
  15. if(func) func = ' '+func+'()';
  16. var line = 'DEPRECATED function call'+func+'. '+msg;
  17. if(console.warn){
  18. console.warn(line);
  19. }else{
  20. console.log(line);
  21. }
  22. if(console.trace) console.trace();
  23. }
  24. /**
  25. * Construct a wrapper function for deprecated function names
  26. *
  27. * This function returns a wrapper function which just calls DEPRECATED
  28. * and the new function.
  29. *
  30. * @param func The new function
  31. * @param context Optional; The context (`this`) of the call
  32. */
  33. function DEPRECATED_WRAP(func, context) {
  34. return function () {
  35. DEPRECATED();
  36. return func.apply(context || this, arguments);
  37. };
  38. }