Posted By

iTony on 06/22/09


Tagged

fix javascript extensions


Versions (?)

Remedial Javascript Functionalities


 / Published in: JavaScript
 

URL: http://javascript.crockford.com/remedial.html

  1. function typeOf(value) {
  2. var s = typeof value;
  3. if (s === 'object') {
  4. if (value) {
  5. if (value instanceof Array) {
  6. s = 'array';
  7. }
  8. } else {
  9. s = 'null';
  10. }
  11. }
  12. return s;
  13. }
  14.  
  15. String.prototype.supplant = function (o) {
  16. return this.replace(/{([^{}]*)}/g,
  17. function (a, b) {
  18. var r = o[b];
  19. return typeof r === 'string' || typeof r === 'number' ? r : a;
  20. }
  21. );
  22. };
  23.  
  24. String.prototype.trim = function () {
  25. return this.replace(/^\s+|\s+$/g, "");
  26. };

Report this snippet  

You need to login to post a comment.