javascript 构造函数方式定义对象(3)


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var Person=function (username,password){
    this.username=username;
    this.password=password;
    if(typeof Person.flag=="undefined"){
        alert("invoked");
        Person.prototype.getInfo=function(){
            alert(this.username+" , "+this.password);
        }
        Person.flag=true;   
    }
}
var p1=new Person("zhangsan","123");
var p2=new Person("lisi","456");
p1.getInfo();
p2.getInfo();
</script>
</head>        
<body>
</body>
</html>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgxdzz.html