Remedial Javascript Functionalities


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your 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. };

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.