0

for example, I create a constructor function called Test,

         function Test(a,b)
         {
               this.a = a;
               this.b = b;
               var test = "test";
         }

When I attempt to view the properties of the Test constructor in firefox debug mode, I don't see these properties (a, b, and test) I define. Why?

constructor Test

3
  • The constructor is just an ordinary function. The properties are in the objects that you create with it. Commented Jun 29, 2018 at 1:04
  • True, I did see the properties through the object but how can I view them from the constructor function? Commented Jun 29, 2018 at 1:09
  • You can't, they're not part of the constructor function. The constructor function just executes that as code. Commented Jun 29, 2018 at 1:12

1 Answer 1

1

a and b are not properties of the constructor. When you create an object using the constructor, the object will get those properties as a result of the assignments. But as far as the constructor itself is concerned, those are just ordinary lines of code, there's nothing special that makes them act as properties.

var t = new Test(1, 2);

If you view t you will see the a and b properties.

test is not a property at all, it's just a local variable inside the constructor. The only way to see it is to set a breakpiont in the constructor and examine the local variables. Variables are not part of a Function object.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.