JavaScript

Arguments to Functions

//Copy property names to a.
//If a is missing, create a new a.
function copyPropertyNamesToArray(o, /*optional*/ a){
        if (!a) {
                a = [];
        };
        for (var p in o) {
                a.push(p);
        }
        return a;
}
        
function getArguments(){
        //can't use join() because arguments is an object (that looks like an array).
        var result = "";
        for (var i =0; i< arguments.length; i++){
                result += arguments[i] + " ";
        }
        return result;
}

function getCaller(){
        return arguments.callee;
}

getArguments(1,2,3)

getArguments('hi', 2)

getArguments()

getCaller()

f = function(x) {
        if (x <= 1){
                return 1;
        }
        return x * arguments.callee(x-1);
}

José M. Vidal .

40 of 65