JS对象与函数纠缠

    function person(name){
        this.name=name;
        //构造函数内的属性 
        this.show=show;  
    }
    function show(){
        alert("Hello :"+this.name);
    }
    
    person.author="OBJECT";
    person.poem="Everything has its object, things are empty...";
    person.Sing=function(){
        alert(person.author+" -> "+person.poem);
    }
    person.prototype=person   //在此演化
    
    person.prototype.marry=function(){
        alert(this.name+" have married")
    }
    var p=new person("张三");
    p.Sing();    
    p.marry();   // 结婚了

posted @ 2012-10-10 20:30  至道中和  阅读(159)  评论(0)    收藏  举报