S13_A3_T2.js (933B)
1 // Copyright 2009 the Sputnik authors. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 info: | 6 The Identifier in a FunctionExpression can be referenced from inside the 7 FunctionExpression's FunctionBody to allow the function calling itself 8 recursively 9 es5id: 13_A3_T2 10 description: > 11 Creating a recursive function that calculates factorial, as a 12 variable. Function calls itself by the name of the variable 13 ---*/ 14 15 var __func = function (arg){ 16 if (arg === 1) { 17 return arg; 18 } else { 19 return __func(arg-1)*arg; 20 } 21 }; 22 23 var fact_of_3 = __func(3); 24 25 ////////////////////////////////////////////////////////////////////////////// 26 //CHECK#1 27 if (fact_of_3 !== 6) { 28 throw new Test262Error("#1: fact_of_3 === 6. Actual: fact_of_3 ==="+fact_of_3); 29 } 30 // 31 ////////////////////////////////////////////////////////////////////////////// 32 33 reportCompare(0, 0);