2
0

moreFuncExpr.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 Test1()
  7. {
  8. write("Declaration Test1")
  9. };
  10. Test1();
  11. var Result1 = function Test1()
  12. {
  13. write("Expression Test1")
  14. };
  15. Test1();
  16. Result1();
  17. var Result2, Test2;
  18. Result2 = function Test2(n)
  19. {
  20. if (n < 0)
  21. {
  22. write("Test2: Less 0");
  23. }
  24. else
  25. {
  26. write("Test2: Greater 0");
  27. Test2(-n);
  28. }
  29. }
  30. Test2 = function Test2(n)
  31. {
  32. write("In second Test2");
  33. };
  34. Result2(2);
  35. var fact, factorial;
  36. fact = function factorial(n)
  37. {
  38. return n<=1?1:n*factorial(n-1)
  39. };
  40. factorial = function factorial(n)
  41. {
  42. return -1
  43. };
  44. write("Test3 factorial : " + fact (3));
  45. function Test4()
  46. {
  47. write("first declaration of Test4")
  48. };
  49. Test4();
  50. function Test4()
  51. {
  52. write("Second declaration of Test4")
  53. };
  54. Test4();
  55. function Test5(n)
  56. {
  57. return n<=1?1:n*Test5(n-1)
  58. };
  59. var Result5 = Test5;
  60. Test5 = function (n)
  61. {
  62. return -1
  63. };
  64. write("Test5 factorial : " + Result5(3));
  65. var Test6 = function Test6()
  66. {
  67. write(Test6)
  68. };
  69. var Result6 = Test6;
  70. Test6 = "Outer Binding";
  71. Result6();