Calling a method in a Javascript Constructor and Accessing Its Variables

后端 未结 3 575
旧巷少年郎
旧巷少年郎 2020-12-24 12:06

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! Than

3条回答
  •  死守一世寂寞
    2020-12-24 12:34

    Solution:

    function ValidateFields(pFormID){
        console.log("ValidateFields Instantiated");
        var aForm = document.getElementById(pFormID);
        this.errArray = new Array();//error tracker
        this.CreateErrorList(); //calling a constructors method
    }
    
    ValidateFields.prototype.CreateErrorList = function(){
       console.log("Create Error List");
       console.log(this.errArray); //this is how to access the constructors variable
    }
    

    Hope this helps anyone who might have a question like this in the future.

提交回复
热议问题