general.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // wrapped by build app
  2. define("dojox/lang/oo/general", ["dijit","dojo","dojox","dojo/require!dojox/lang/oo/Decorator"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.lang.oo.general");
  4. dojo.require("dojox.lang.oo.Decorator");
  5. (function(){
  6. var oo = dojox.lang.oo, md = oo.makeDecorator, oog = oo.general,
  7. isF = dojo.isFunction;
  8. // generally useful decorators
  9. oog.augment = md(function(name, newValue, oldValue){
  10. // summary: add property, if it was not defined before
  11. return typeof oldValue == "undefined" ? newValue : oldValue;
  12. });
  13. oog.override = md(function(name, newValue, oldValue){
  14. // summary: override property only if it was already present
  15. return typeof oldValue != "undefined" ? newValue : oldValue;
  16. });
  17. oog.shuffle = md(function(name, newValue, oldValue){
  18. // summary: replaces arguments for an old method
  19. return isF(oldValue) ?
  20. function(){
  21. return oldValue.apply(this, newValue.apply(this, arguments));
  22. } : oldValue;
  23. });
  24. oog.wrap = md(function(name, newValue, oldValue){
  25. // summary: wraps the old values with a supplied function
  26. return function(){ return newValue.call(this, oldValue, arguments); };
  27. });
  28. oog.tap = md(function(name, newValue, oldValue){
  29. // summary: always returns "this" ignoring the actual return
  30. return function(){ newValue.apply(this, arguments); return this; };
  31. });
  32. oog.before = md(function(name, newValue, oldValue){
  33. // summary:
  34. // creates a chain of calls where the new method is called
  35. // before the old method
  36. return isF(oldValue) ?
  37. function(){
  38. newValue.apply(this, arguments);
  39. return oldValue.apply(this, arguments);
  40. } : newValue;
  41. });
  42. oog.after = md(function(name, newValue, oldValue){
  43. // summary:
  44. // creates a chain of calls where the new method is called
  45. // after the old method
  46. return isF(oldValue) ?
  47. function(){
  48. oldValue.apply(this, arguments);
  49. return newValue.apply(this, arguments);
  50. } : newValue;
  51. });
  52. })();
  53. });