home *** CD-ROM | disk | FTP | other *** search
/ Minami 83 / MINAMI83.iso / Extra / DivXInstaller.exe / $PLUGINSDIR / GoogleToolbarFirefox.msi / xpi / amulet-jslib / google3 / lang.js < prev    next >
Text File  |  2006-08-07  |  4KB  |  199 lines

  1. function isDef(val) {
  2. return typeof val != "undefined";
  3. }
  4. function isNull(val) {
  5. return val === null;
  6. }
  7. function isArray(val) {
  8. return isObject(val) && val.constructor == Array;
  9. }
  10. function isString(val) {
  11. return typeof val == "string";
  12. }
  13. function isBoolean(val) {
  14. return typeof val == "boolean";
  15. }
  16. function isNumber(val) {
  17. return typeof val == "number";
  18. }
  19. function isFunction(val) {
  20. return typeof val == "function";
  21. }
  22. function isObject(val) {
  23. return val && typeof val == "object";
  24. }
  25. function getObjectProps(obj) {
  26. var ret = [];
  27. for (var p in obj) {
  28. ret.push(p);
  29. }
  30. return ret;
  31. }
  32. function isEmptyObject(val) {
  33. if (!isObject(val)) {
  34. return false;
  35. }
  36. for (var p in val) {
  37. return false;
  38. }
  39. return true;
  40. }
  41. var getHashCode;
  42. var removeHashCode;
  43. (function () {
  44. var hashCodeProperty = "lang_hashCode_";
  45. getHashCode = function(obj) {
  46. if (!obj[hashCodeProperty]) {
  47. obj[hashCodeProperty] = ++getHashCode.hashCodeCounter_;
  48. }
  49. return obj[hashCodeProperty];
  50. };
  51. removeHashCode = function(obj) {
  52. obj[hashCodeProperty] = undefined;
  53. };
  54. getHashCode.hashCodeCounter_ = 0;
  55. })();
  56. String.prototype.startsWith = function(prefix) {
  57. if (this.length < prefix.length) {
  58. return false;
  59. }
  60. if (this.substring(0, prefix.length) == prefix) {
  61. return true;
  62. }
  63. return false;
  64. }
  65. String.prototype.trim = function() {
  66. return this.replace(/^\s+|\s+$/g, "");
  67. }
  68. String.prototype.subs = function() {
  69. var ret = this;
  70. for (var i = 0; i < arguments.length; i++) {
  71. ret = ret.replace(/\%s/, String(arguments[i]));
  72. }
  73. return ret;
  74. }
  75. if (!Function.prototype.apply) {
  76. Function.prototype.apply = function(oScope, args) {
  77. var sarg = [];
  78. var rtrn, call;
  79. if (!oScope) oScope = window;
  80. if (!args) args = [];
  81. for (var i = 0; i < args.length; i++) {
  82. sarg[i] = "args[" + i + "]";
  83. }
  84. call = "oScope.__applyTemp__.peek().(" + sarg.join(",") + ");";
  85. if (!oScope.__applyTemp__) {
  86. oScope.__applyTemp__ = [];
  87. }
  88. oScope.__applyTemp__.push(this);
  89. rtrn = eval(call);
  90. oScope.__applyTemp__.pop();
  91. return rtrn;
  92. }
  93. }
  94. if (!Array.prototype.push) {
  95. Array.prototype.push = function() {
  96. for (var i = 0; i < arguments.length; i++) {
  97. this[this.length] = arguments[i];
  98. }
  99. return this.length;
  100. }
  101. }
  102. if (!Array.prototype.pop) {
  103. Array.prototype.pop = function() {
  104. if (!this.length) {
  105. return;
  106. }
  107. var val = this[this.length - 1];
  108. this.length--;
  109. return val;
  110. }
  111. }
  112. Array.prototype.peek = function() {
  113. return this[this.length - 1];
  114. }
  115. if (!Array.prototype.shift) {
  116. Array.prototype.shift = function() {
  117. if (this.length == 0) {
  118. return; // return undefined
  119. }
  120. var val = this[0];
  121. for (var i = 0; i < this.length - 1; i++) {
  122. this[i] = this[i+1];
  123. }
  124. this.length--;
  125. return val;
  126. }
  127. }
  128. if (!Array.prototype.unshift) {
  129. Array.prototype.unshift = function() {
  130. var numArgs = arguments.length;
  131. for (var i = this.length - 1; i >= 0; i--) {
  132. this[i + numArgs] = this[i];
  133. }
  134. for (var j = 0; j < numArgs; j++) {
  135. this[j] = arguments[j];
  136. }
  137. return this.length;
  138. }
  139. }
  140. if (!Array.prototype.forEach) {
  141. Array.prototype.forEach = function(callback, scope) {
  142. for (var i = 0; i < this.length; i++) {
  143. callback.apply(scope, [this[i]]);
  144. }
  145. }
  146. }
  147. function bind(fn, self, var_args) {
  148. var boundargs = fn.boundArgs_ || [];
  149. boundargs = boundargs.concat(Array.prototype.slice.call(arguments, 2));
  150. if (typeof fn.boundSelf_ != "undefined") {
  151. self = fn.boundSelf_;
  152. }
  153. if (typeof fn.foundFn_ != "undefined") {
  154. fn = fn.boundFn_;
  155. }
  156. var newfn = function() {
  157. var args = boundargs.concat(Array.prototype.slice.call(arguments));
  158. return fn.apply(self, args);
  159. }
  160. newfn.boundArgs_ = boundargs;
  161. newfn.boundSelf_ = self;
  162. newfn.boundFn_ = fn;
  163. return newfn;
  164. }
  165. Function.prototype.bind = function(self, var_args) {
  166. return bind.apply(
  167. null, [this, self].concat(Array.prototype.slice.call(arguments, 1)));
  168. }
  169. function partial(fn, var_args) {
  170. return bind.apply(
  171. null, [fn, null].concat(Array.prototype.slice.call(arguments, 1)));
  172. }
  173. Function.prototype.partial = function(var_args) {
  174. return bind.apply(
  175. null, [this, null].concat(Array.prototype.slice.call(arguments)));
  176. }
  177. function bindMethods(obj) {
  178. for (var p in obj) {
  179. if (isFunction(obj[p])) {
  180. obj[p] = obj[p].bind(obj);
  181. }
  182. }
  183. }
  184. Function.prototype.inherits = function(parentCtor) {
  185. var tempCtor = function(){};
  186. tempCtor.prototype = parentCtor.prototype;
  187. this.superClass_ = parentCtor.prototype;
  188. this.prototype = new tempCtor();
  189. }
  190. Function.prototype.mixin = function(props) {
  191. for (var x in props) {
  192. this.prototype[x] = props[x];
  193. }
  194. if (isFunction(props['toString']) &&
  195. props['toString'] != this.prototype['toString']) {
  196. this.prototype.toString = props.toString
  197. }
  198. }
  199.