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 3302246
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:49:55+00:00 2026-05-17T20:49:55+00:00

I have a Person javascript class like function Person(_name, _id, _salary){ this.Name = _name;

  • 0

I have a Person javascript class like

function Person(_name, _id, _salary){
    this.Name = _name;
    this.Id = _id;
    this.Salary = _salary;
}

First, i want to overload constructor function with:

function Person( _person ){
    this.Name = _person.Name;
    this.Salary = _person.Salary;
    this.Id = _person.Id;
}

But whatever i do, it goes to the first function …!?

Second, i have some functions for this javascript class like:

Person.prototype.f_IncreaseSalary = function( _percentage ){
    this.Salary *= _percentage;
}

What i am doing now is:

  1. Send string from web service like new Person('cem','1000','15000')
  2. eval the string on client side like:

    dataType:json,
    success:function(msg){
    globalObj = eval(msg.d);
    },

  3. and use the javascript object with its functions. globalObj.f_IncreaseSalary(0.2);

But i think i should return the string within json, like:
"Person" : {"name":"Cem", "id":1000, "salary":15000 }

How can i bind the javascript methods of the Person classs to the json object…?

  • 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-17T20:49:55+00:00Added an answer on May 17, 2026 at 8:49 pm

    It’s not possible in ECMA-/Javascript to “overload” a method/function like this.

    A good workaround is to check the arguments object, like

    function Person(){
       if(typeof arguments[0] === 'object'){
          // addional checks 
          this.Name   = arguments[0].Name;
          this.Salary = arguments[0].Salary;
          // etc.
       }
       else if(arguments.length === 2){
          this.Name   = arguments[0];
          this.Salary = arguments[1];
          // etc.
       }
    }
    

    I don’t think I understand your second question, “how to bind the javascript methods to a json object”.

    You would need to “parse” the json string into a javascript object anyway. That can be done by using window.JSON.parse(<jsonstring>) in “modern” browsers. Older browsers (like IE7) need the json2.js from http://www.json.org to offer the same functionality.

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

Sidebar

Related Questions

I have many JavaScript objects in my application, something like: function Person(age) { this.age
I have a Person and an Organisation Entity: Person looks like this: public class
I have a class like this : public class Person { public string Address
I have a Person Class and based on some help I received in this
I created a function in javascript like that: function addNewManufacturer() { var name =
Javascript rookie here. I have a small page with a first name/last name and
I have class Person class person{ int ID ; sting FirstName ; string Last
I have a Person class. A Person can have an associated control. Can I
I have a Person class. A person class contains a collection of Friends (also
I have a person class, then have a family class where I have a

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.