Javascript Function Overloading via Arguments Checking

Description

Javascript Function Overloading via Arguments Checking

// Simple overloading using argument hashes
function describeBook(args) {
  if (args.name)
    console.log("Name: " + args.name);
  if (args.pages)
    console.log("Pages: " + args.pages);
  if (args.chapters)
    console.log("Chapters: " + args.chapters);
  if (args.author)
    console.log("Author: " + args.author);
  if (args.published)
    console.log("Publish Date: " + args.published);
  if (args.type)//w w  w. j  a  v a  2s.c  o  m
    console.log("Type: " + args.type);
  if (args.section)
    console.log("Section: " + args.section);  
}

describeBook({name:'Gone with the Wind', author: 'Margaret Mitchell', section:'Historical Fiction'});



PreviousNext

Related