a3e9acb29ec87bb0a583ac6654de187c5a998ef0.svn-base 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. if (!dojo._hasResource["dojox.lang.utils"]) { // _hasResource checks added by
  2. // build. Do not use
  3. // _hasResource directly in your
  4. // code.
  5. dojo._hasResource["dojox.lang.utils"] = true;
  6. dojo.provide("dojox.lang.utils");
  7. (function() {
  8. var empty = {}, du = dojox.lang.utils;
  9. dojo.mixin(dojox.lang.utils, {
  10. coerceType : function(target, source) {
  11. switch (typeof target) {
  12. case "number" :
  13. return Number(eval("(" + source + ")"));
  14. case "string" :
  15. return String(source);
  16. case "boolean" :
  17. return Boolean(eval("(" + source + ")"));
  18. }
  19. return eval("(" + source + ")");
  20. },
  21. updateWithObject : function(target, source, conv) {
  22. // summary: updates an existing object in place with
  23. // properties from an "source" object.
  24. // target: Object: the "target" object to be updated
  25. // source: Object: the "source" object, whose properties
  26. // will be used to source the existed object.
  27. // conv: Boolean?: force conversion to the original type
  28. if (!source) {
  29. return target;
  30. }
  31. for (var x in target) {
  32. if (x in source && !(x in empty)) {
  33. var t = target[x];
  34. if (t && typeof t == "object") {
  35. du.updateObject(t, source[x]);
  36. } else {
  37. target[x] = conv ? du.coerceType(t,
  38. source[x]) : dojo.clone(source[x]);
  39. }
  40. }
  41. }
  42. return target; // Object
  43. },
  44. updateWithPattern : function(target, source, pattern, conv) {
  45. // summary: updates an existing object in place with
  46. // properties from an "source" object.
  47. // target: Object: the "target" object to be updated
  48. // source: Object: the "source" object, whose properties
  49. // will be used to source the existed object.
  50. // pattern: Array: an array of properties to be copied
  51. // conv: Boolean?: force conversion to the original type
  52. if (!source || !pattern) {
  53. return target;
  54. }
  55. for (var x in pattern) {
  56. if (x in source && !(x in empty)) {
  57. target[x] = conv ? du.coerceType(pattern[x],
  58. source[x]) : dojo.clone(source[x]);
  59. }
  60. }
  61. return target; // Object
  62. }
  63. });
  64. })();
  65. }