Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3330990
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:32:37+00:00 2026-05-17T23:32:37+00:00

////////////////////////////////////////////////////////////////////////////// <!– To change this template, choose Tools | Templates and open the template

  • 0
//////////////////////////////////////////////////////////////////////////////

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
// 3 constructor functions of Person, Book, and Library
function Person(fname,lname)
{
    this.firstName = fname;
    this.lastName = lname;
}

function Book(booktitle,pages,price)
{
    this.bookTitle = booktitle;
    this.pages = pages;
    this.price = price;
    this.authors = new Array(arguments.length-3);
    for(i=0;i<arguments.length-3;i++)
    {
     this.authors[i] = arguments[i+3];
    }
}

function Library()
{
    this.books = new Array(arguments.length);
    for(i=0;i<arguments.length;i++)
    { 
     this.books[i] = arguments[i];
    }
    this.totalPrice = function(){
    var totalCost = 0;
    for(i=0;i<this.books.length;i++)
    {
   totalCost += this.books[i].price;
    }
    return totalCost;
    }
    this.averagePrice = new Function("return this.totalPrice()/this.books.length");
    var flag;
    this.getBook = function(name){
        for(i=0;i<this.books.length;i++)
    {
        if(this.books[i].bookTitle == name )
        {
         this.flag = i;
        }
    }


    }

    this.getAuthors = function(){
   var toSay = "";

     for(j=0;j<this.books[this.flag].authors.length;j++){
       var authName = 
       this.books[this.flag].authors[j].lastName + " " + 
       this.books[this.flag].authors[j].firstName + "\t";
       if(toSay.indexOf(authName)!=-1)
       continue;
       toSay+=""+authName;
     }

 return toSay;
 }
}


var john = new Person("Smith", "John");
var jack = new Person("Simpson", "Jack");
var bobby = new Person("Franklin", "Bobby");
var albert = new Person("Camus", "Albert");
var java = new Book("Dummy Java", 1000, 29.95, john, jack);
var php = new Book("Dummy PHP", 300, 19.95, john);
var xml = new Book("Dummy XML", 150, 9.95, bobby, albert);
var js = new Book("Dummy JavaScript", 2000, 49.95, albert);
var lib = new Library(java, php, xml, js);
alert(lib.totalPrice()); // output 109.8
alert(lib.averagePrice()); // output 27.45
lib.getBook("Dummy XML");
alert(lib.getAuthors()); // output John Smith, Jack Simpson
</script>
</head>
<body>
</body>
</html>



/////////////////////////////////////////////////////////////////////

Instead of using the below two statements

lib.getBook("Dummy XML");
alert(lib.getAuthors()); // output John Smith, Jack Simpson

it works fine to produce the above output. but i want to produce the abouve output using nested methods.

i want to use a single statement alert(lib.getBook("Dummy XML").getAuthors()); to produce the same output ( // output John Smith, Jack Simpson)

Please help me on how to call a method in a method.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:32:37+00:00Added an answer on May 17, 2026 at 11:32 pm

    It’s called method chaining. Have the functions return this.

       this.getBook = function(name){
            for(i=0;i<this.books.length;i++) {
               if(this.books[i].bookTitle == name )          {
                  this.flag = i;
               }
            }
    
            return this;
       }
    

    then you can call another method on the return of lib.getBook("Dummy XML")….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My NSXMLParser breaks on this string: <title>AAA &#8211; BCDEFGQWERTYUIO</title> I parsed it in this
Possible Duplicate: replace all occurrences in a string I found this question/answer: Use JavaScript
i have this code: <?php $valid_ext = array(pdf, doc); $args = array( 'post_type' =>
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm having troubles with my meta tags with Open Graph. It seems as though
I would like to count the length of a string with PHP. The string
I've got the following login script.. <?php $name = $_POST[name]; $password = $_POST[password]; $query
So to start, I have an array of XML files. These files need to
I'm struggling to position the second level of a dropdown nav menu and was
Have a webpage that will be viewed by mainly IE users, so CSS3 is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.