On the _javascript techniques of instance object, class object, local variable (local function) in JS function

Source: Internet
Author: User

Defined

function person (national,age)
    {
      this.age = age;  instance objects, with each example different
      person.national = National;  Class object, used instance public
      var bb = 0;//local variable, outside inaccessible (similar to local function)
    }

Call

var p = new Person ("China");
      Document.writeln ("Age:" + p.age);
      Document.writeln ("Object National:" + p.national);
      Document.writeln ("Class National:" + person.national);
      Document.writeln ("Local var:" + p.bb);

      var p2 = new Person ("USA");
      Document.writeln ("</br>");
      Document.writeln ("Age:" + p2.age);
      Document.writeln ("Object National:" + p2.national);
      Document.writeln ("Class National:" + person.national);
      Document.writeln ("Local var:" + p2.bb);

      Document.writeln ("</br>");
      Document.writeln ("Class National:" + person.national);
      Age:29 object national:undefined Class National: China local var:undefined 
      //age:31 object national:undefined class National: United States local var:undefined 
      //class National: United States

This article on the JS function of the instance object, class object, local variables (local function) is small to share all the content of everyone, hope to give you a reference, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.