浅谈js函数中的实例对象、类对象、局部变量(局部函数)
时间:2021-04-18 09:49:07|栏目:JavaScript代码|点击: 次
定义
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:美国
上一篇:在JavaScript中构建ArrayList示例代码
栏 目:JavaScript代码
本文标题:浅谈js函数中的实例对象、类对象、局部变量(局部函数)
本文地址:http://www.codeinn.net/misctech/103612.html






