JS 面向对象编程 程序集

来源:互联网 发布:deepinms优化xp程序 编辑:程序博客网 时间:2024/09/21 09:02

//
var People=function(name,address){
        this.t_name=name;  
        var v_name=name;
   
        this.address=address;
        this.who=function(){
                alert('a:'+this.t_name);//a:zengle
                alert('b:'+v_name);//b:zengle
        }
        var where=function(){
                alert(this.address);
       }
}

var people=new People('zengle','福州');
people.who();
alert('c:'+people.t_name);//c:zengle
alert('d:'+people.v_name);//d:undefined
people.where();//错误: 对象不支持此属性或方法(people.where is not a function)