浅谈js函数中的实例对象、类对象、局部变量(局部函数)

时间:2016-11-20    点击:167   

定义

function Person(national,age)
    {
      this.age = age;  //实例对象,每个示例不同
      Person.national = national;  //类对象,所用实例公用
      var bb = 0; //局部变量,外面不能访问(类似局部函数)
    }

调用

var p = new Person("中国", 29);
      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("美国", 31);
      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:中国 local var:undefined 
      //age:31 object national:undefined Class national:美国 local var:undefined 
      //Class national:美国

以上这篇浅谈js函数中的实例对象、类对象、局部变量(局部函数)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持本站。

js原生实现FastClick事件的实例
常用原生js自定义函数总结
浅谈js之字面量、对象字面量的访问、关键字in的用法
浅谈jquery选择器 :first与:first-child的区别
关于js函数解释(包括内嵌,对象等)
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved