DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Nikola has posted 1 posts at DZone. View Full User Profile

JavaScript function overloading

  • submit to reddit
var def = function(functions, parent) {
 return function() {
    var types = [];
    var args = [];
    eachArg(arguments, function(i, elem) {
    if(functions.hasOwnProperty(types.join())) {
        return functions[types.join()].apply(parent, args);
    } else {
        if (typeof functions === 'function')
            return functions.apply(parent, args);
        if (functions.hasOwnProperty('default'))
            return functions['default'].apply(parent, args);        

var eachArg = function(args, fn) {
 var i = 0;
 while (args.hasOwnProperty(i)) {
    if(fn !== undefined)
        fn(i, args[i]);
 return i-1;

var whatis = function(val) {

 if(val === undefined)
    return 'undefined';
 if(val === null)
    return 'null';

 var type = typeof val;

 if(type === 'object') {
    if(val.hasOwnProperty('length') && val.hasOwnProperty('push'))
        return 'array';
    if(val.hasOwnProperty('getDate') && val.hasOwnProperty('toLocaleTimeString'))
        return 'date';
        type = 'number';
    if(val.hasOwnProperty('substring') && val.hasOwnProperty('length'))
        return 'string';

 if(type === 'number') {
    if(val.toString().indexOf('.') > 0)
        return 'float';
        return 'int';

 return type;

var out = def({
    'int': function(a) {
        alert('Here is int '+a);

    'float': function(a) {
        alert('Here is float '+a);

    'string': function(a) {
        alert('Here is string '+a);

    'int,string': function(a, b) {
        alert('Here is an int '+a+' and a string '+b);
    'default': function(obj) {
        alert('Here is some other value '+ obj);


out(2, 'robot');


Victor Arnold replied on Sat, 2014/02/08 - 3:07pm

 The first aspect to consider is staff turnover, because a low turnover rate indicates that management recognizes and invests in quality technicians. Life Experience Degrees

Jose Jones replied on Sat, 2013/12/28 - 7:07am

It might be difficult to find out which specific person will be working on the truck, but it is still possible to get a feel for the overall workforce. The first aspect to consider is staff turnover, because a low turnover rate indicates that management recognizes and invests in quality technicians. One should also ask about how technically proficient or trained employees are, which could be determined by asking what kind of training programs the company uses for new hires. Keep in mind there is no substitute for experience, so one should ask how many average years of experience an organization's technicians have.

Trucking Hawaii 

Perry Kate replied on Thu, 2013/09/05 - 6:12pm

Sagive Seo replied on Fri, 2013/06/21 - 4:17pm

Share an example where i might need to use such function?

Neev Kidman replied on Mon, 2013/06/17 - 4:31pm

I studied JavaScript to make strong my web development skills. I was always very week in function overloading of JavaScript. But when I read it then my all confusions have been vanished. So whenever any students comes to me to buy dissertation UK  made on JavaScript then I can help him now.

Perry Kate replied on Thu, 2013/06/13 - 8:00pm

Shushan Ele replied on Mon, 2013/05/13 - 7:51am

 Our highly qualified and highly skilled essay writer uk   are available. Avail their finest services now and enjoy guaranteed A+. Our writers will write a genuine. The internet is awash with people offering to write essays for students. Get essay help from our essay writers to ensure that your essay is the best.