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

  • SEARCH
  • Home
  • 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 6977917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:41:13+00:00 2026-05-27T17:41:13+00:00

Given these code var Person = function(firstName, lastName) { this.firstName = firstName; this.lastName =

  • 0

Given these code

var Person = function(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
};

Person.prototype = {
  toString: function() { return this.firstName + ' ' + this.lastName; }
};

var test4 = Object.create(Person);
test4.firstName = "Phat4";
test4.lastName = "Wang4";
console.log(test4.toString === Object.toString); // true
console.log(test4.toString === Function.toString); // true

var test5 = { firstName: "Phat5", lastName: "Wang5" };
console.log(test5.toString === test4.toString); // false
console.log(test4.toString === Function.toString); // true
console.log(test5.toString === Object.prototype.toString); // true

console.log(test5.toString()); // [object Object]
console.log(test4.toString()); // Function.prototype.toString called on incompatible object

Why does the last line console.log(test4.toString()) throws error ? It shows that test4.toString is not like test5.toString but I don’t get it ..

Ps. I’ve tried searching the threads and still cannot answer myself. Sorry if this duplicates with any.

  • 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-27T17:41:14+00:00Added an answer on May 27, 2026 at 5:41 pm

    Instead of this:

    var test4 = Object.create(Person);
    

    You should be doing:

    var test4 = Object.create(Person.prototype);
    

    The way you had it, test4 had the Person function in its prototype chain, not the intended prototype object that has your toString method.

    Because of this, it was using a toString() method that is apparently anticipating being called against a Function object.

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

Sidebar

Related Questions

Given the following code: var people = new List<person>(){ new person { Name =
For instance, take this piece of code: var person = new Person(); or for
Given the Java code below, what's the closest you could represent these two static
There's something very unsatisfactory about this code: /* Given a command string in which
Given these tables: create table Orders ( Id INT IDENTITY NOT NULL, primary key
This is easier to explain with an example. Given these two classes: public class
I used the code from Why is this slideshow flickering? which peter has given
I have an object model that looks like this (pseudo code): class Product {
Given following code: VAR X PIC S9(7)V9(2). VAR Y PIC X(15) Following code having
Given the following code, is there a way I can call class A's version

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.