SoFunction
Updated on 2025-04-06

A brief discussion on instance objects, class objects, and local variables (local functions) in js functions

definition

function Person(national,age)
    {
       = age;  //Instance object, each example is different       = national;  //Class object, the instance used is public      var bb = 0; // Local variables cannot be accessed outside (similar to local functions)    }

Call

var p = new Person("China", 29);
      ("age:" + );
      ("object national:" + );
      ("Class national:" + );
      ("local var:" + );

      var p2 = new Person("USA", 31);
      ("</br>");
      ("age:" + );
      ("object national:" + );
      ("Class national:" + );
      ("local var:" + );

      ("</br>");
      ("Class national:" + );
      //age:29 object national:undefined Class national:China local var:undefined      //age:31 object national:undefined Class national:United local var:undefined      //Class national:USA

The above brief discussion of instance objects, class objects, and local variables (local functions) in js functions is all the content I share with you. I hope you can give you a reference and I hope you can support me more.