下面小编就为大家带来一篇浅谈js函数中的实例对象、类对象、局部变量(局部函数)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
定义
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函数中的实例对象、类对象、局部变量(局部函数)简单介绍的详细内容。