JS对象与函数纠缠

来源:互联网 发布:vb vc 编辑:程序博客网 时间:2024/04/28 16:40
    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();   // 结婚了