javascript overloading

javascript overloading

function test() {
    var args_len = arguments.length;
    switch(args_len) {
        case 0:
            // statement.....;
            $('div').text('args_len: 0');
            break;
        case 1:
            if(typeof arguments[0]  === 'number') {
                // statement.....;
                $('div').text('args_len: 1, type: number, value: ' + arguments[0]);
            }else if(typeof arguments[0] === 'string') {
                // statement.....;
                $('div').text('args_len: 1, type: string, value: ' + arguments[0]);
            }
            break;
        case 2:
            $('div').text('args_len: 2, value: ' + arguments[0] + ',' + arguments[1]);
            break;
    }
}
test();
Like what you read? Give Hyung-Ro Ahn a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.