浅谈js函数中的实例对象、类对象、局部变量(局部函数)
定义
functionPerson(national,age)
{
this.age=age;//实例对象,每个示例不同
Person.national=national;//类对象,所用实例公用
varbb=0;//局部变量,外面不能访问(类似局部函数)
}
调用
varp=newPerson("中国",29);
document.writeln("age:"+p.age);
document.writeln("objectnational:"+p.national);
document.writeln("Classnational:"+Person.national);
document.writeln("localvar:"+p.bb);
varp2=newPerson("美国",31);
document.writeln("</br>");
document.writeln("age:"+p2.age);
document.writeln("objectnational:"+p2.national);
document.writeln("Classnational:"+Person.national);
document.writeln("localvar:"+p2.bb);
document.writeln("</br>");
document.writeln("Classnational:"+Person.national);
//age:29objectnational:undefinedClassnational:中国localvar:undefined
//age:31objectnational:undefinedClassnational:美国localvar:undefined
//Classnational:美国
以上这篇浅谈js函数中的实例对象、类对象、局部变量(局部函数)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短