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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:10:29+00:00 2026-05-13T09:10:29+00:00

Why if i try: Object(n) //Constructor { this.member = n; } Object.prototype.alertX = function()//

  • 0

Why if i try:

Object(n) //Constructor
{
this.member = n;
}

Object.prototype.alertX = function()// Method
{
alert(this.member);
}

foo = new Object(4);
Object.alertX;

I get “this. member is not defined”.

How can i access the constructor’s member inside one of its methods?

EDITED: my original purpose is to have an internal method access the already created object member, not to access the object’s method from creating another object, the object is already created!

Thanks!

EDITED 2:

Tried this:

var fooObj = function(x,y,z){ // Map object constuctor.
    this.x = x;
    this.y = y;
    this.z = y;
}
fooObj.prototype.test = function(){
    alert(this.x);
}

***initialization****
something = new fooObj();
something.otherMethod(x,y,z); <--- draws an object, a canvas, for example.
document.getElementById('canvas').addEventListener('mouseup', something.test, false);

When i press over the object, should fire of the alert, but get the this.x not defined. Do i have to give it a value? The object was already created and executed one of its functions!

  • 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-13T09:10:29+00:00Added an answer on May 13, 2026 at 9:10 am

    Edited again…

    Your constructor accepts 3 arguments and sets them on the object. You are not feeding them in the initial invocation. Now, assuming you did not leave even more information out, change it to:

    var fooObj = function(x,y,z){ // Map object constuctor.
        this.x = x;
        this.y = y;
        this.z = y;
    }
    fooObj.prototype.test = function(){
        alert(this.x);
    }
    
    var something = new fooObj(x,y,z);
    something.otherMethod(x,y,z); <--- draws an object, a canvas, for example.
    

    Otherwise if you are leaving something out, please paste an ENTIRE replica of your code to not waste time.

    Again, to re-iterate, make sure the properties are being set. Otherwise the explanation is that they’re not being set, simple explanation.

    function Member(n) {
        this.member = n;
    };
    
    Member.prototype.memberNumber = function() { alert( this.member ) };
    
    var john = new Member(1);
    john.memberNumber()
    

    Or

    function Custom() {
        this.member = 2;
    };
    
    Object.prototype.alertX = function() {
        alert( this.member )
    }
    
    var x = new Custom();
    x.alertX()
    

    “EDITED: my original purpose is to
    have an internal method access the
    already created object member, not to
    access the object’s method from
    creating another object, the object is
    already created!”

    Whatever constructor you used or however you set the property, make sure it was set. Then just attach a method to the prototype alerting this.member and it will work, if not you did not properly set the member property. Simple as that.

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

Sidebar

Related Questions

if in a literal object i try to reference a function using this inside
Whenever I try to extend the Object prototype, I get an error: Error #1056:
I'm try to create a new list object. I set the new object to
I have a field that may be blank, so I need to use Object.try,
I have some trouble when I try to map object to int . My
my classes seem to be mapped correctly (if I try persist an object it
I try to cast an object to my Action class, but it results in
I try to change a string into an object using eval but failed. var
When I try to initialize an object using the Object Initializer, ReSharper always inserts
When I try to create a COM object in VB script on a Windows

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.