Nora
Nora

Reputation: 65

How to view constructor properties of a function in javascript?

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

Upvotes: 0

Views: 432

Answers (1)

Barmar
Barmar

Reputation: 781310

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.

Upvotes: 1

Related Questions