/* Append the names of the enumerable properties of object o to the array a, and return a. If a is omitted or null, create and return a new array */ function copyPropertyNamesToArray(o, /* optional */ a) { if ( ! a) a = []; // /If undefined or null , use a blank array for ( var perperty in o) a.push(perperty) return ; } /* arguments 类似 Math.max() */ function max( /* ..... */ ) { var m = Number.NEGATIVE_INFINITY; // //Loop through all the arguments , looking for, and // // remembering, the biggest for ( var i = 0 ; i < arguments.length; i ++ ) if (arguments[i] > m) m = arguments[i]; return m; } /* 判断传递给函数的参数个数是否符合要求 */ function check(args) { var actual = args.length; var expected = args.callee.length; if (actual != expected) { throw new Error( " Wrong number of arguments: expected: " + expected + " ; actually passed " + actual); } } function f(x, y, z) { check(arguments); return x + y + z; } /* 程序员偶尔会想要编写一个通过调用来记住一个值的函数。这个值不能存储在一个局部变量中,因为调用对象不能通过调用来维持。尽量不用全局变量 */ uniqueId = function () { if ( ! arguments.callee.id) arguments.callee.id = 0 ; return arguments.callee.id ++ ; } CuniqueId = ( function () { // The call object of this function holds our value var id = 0 ; // this is the private persistent value // The outer function returns a nested function that has access // to the persistent value. It is the nested function we're storing // in the variable uniqueId above return function () { return id ++ }; // Return and increment })(); // Invoke the outer function after defining it.