charCodeAt.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function write(v) { WScript.Echo(v + ""); }
  6. function allChars(s, len) {
  7. write("AllChars : " + s + ". Length : " + len);
  8. for (var i=0; i<len; ++i) {
  9. write(s.charCodeAt(i));
  10. }
  11. }
  12. function firstChar(obj, showOutput) {
  13. if (showOutput != false)
  14. write(">> FirstChar : " + obj);
  15. try {
  16. write(String.prototype.charCodeAt.call(obj, 0));
  17. } catch (e) {
  18. write("Got a exception. " + e.message);
  19. return;
  20. }
  21. if (showOutput != false)
  22. write("<< FirstChar.");
  23. }
  24. allChars("Hello", 5);
  25. allChars("Hello" + "World", 10);
  26. var objs = [ /*null,*/ undefined, 0, 1.1, new Number(10), new String("Hello"),
  27. true, false, new Boolean(true), new Object() ];
  28. firstChar(null, false);
  29. for (var i=0; i<objs.length; ++i) {
  30. firstChar(objs[i]);
  31. }