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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:34:18+00:00 2026-05-13T19:34:18+00:00

I am trying to call a method from the constructor of my javascript constructor,

  • 0

I am trying to call a method from the constructor of my javascript constructor, is this possible and if so, I can’t seem to get it working, any insight would be great! Thanks!

function ValidateFields(pFormID){
    var aForm = document.getElementById(pFormID);
    this.errArray = new Array();//error tracker
    this.CreateErrorList();
}
/*
 * CreateErrorList()
 * Creates a list of errors:
 *   <ul id="form-errors">
 *    <li>
 *     You must provide an email.
 *    </li>
 *   </ul>
 * returns nothing
 */
 ValidateFields.prototype.CreateErrorList = function(formstatid){
     console.log("Create Error List");
 }

I got it to work with what is above, but I can’t seem to access the ‘errArray’ variable in CreateErrorList function.

  • 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-13T19:34:18+00:00Added an answer on May 13, 2026 at 7:34 pm

    Yes, it is possible, when your constructor function executes, the this value has already the [[Prototype]] internal property pointing to the ValidateFields.prototype object.

    Now, by looking at the your edit, the errArray variable is not available in the scope of the CreateErrorList method, since it is bound only to the scope of the constructor itself.

    If you need to keep this variable private and only allow the CreateErrorList method to access it, you can define it as a privileged method, within the constructor:

    function ValidateFields(pFormID){
      var aForm = document.getElementById(pFormID);
      var errArray = [];
    
      this.CreateErrorList = function (formstatid){
        // errArray is available here
      };
      //...
      this.CreateErrorList();
    }
    

    Note that the method, since it’s bound to this, will not be shared and it will exist physically on all object instances of ValidateFields.

    Another option, if you don’t mind to have the errArray variable, as a public property of your object instances, you just have to assign it to the this object:

    //..
    this.errArray = [];
    //..
    

    More info:

    • Private Members in JavaScript
    • Closures
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to call my Javascript method from my java in GWT below
Possible Duplicate: javascript object, access variable property name? I'm trying to call a method
I am trying to call a ruby method from erb file. This method takes
I'm trying to call method from .jar But when I want to declare array
I'm trying to call a method from another class with a simple button in
Im trying to call a method that will add or subtract 1 from a
i am trying to call a navite method defined in c++ from java, the
I am trying to make a call to a Parent class method from a
I am trying to call a method I have written in C# from VBScript.
Hello I am trying to call a method (fileReader) that is using openFileInput(filename) from

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.