( FEED rss2.0 )

sed /sshd/p -n /var/log/auth.log > /log/sshd.log » 21 days ago

chinese继承自person,并新建了个方法:saylove.在onload中测试new一个chinese.并直接调用person中定义的say和from方法.最后调用chinese增加的saylove方法.返回ok.那么这应该就算继承了吧.

js:

$(function(){ //this code need jquery support
    $(”a.say”).click(function(){
        var name = $(this).attr(”name”);
        var sex = $(this).attr(”sex”);
        var area = $(this).attr(”area”);
        ihao = new chinese(name,sex,area);
        ihao.say();
        ihao.from();
        ihao.saylove();
        return false;
    });
});
function chinese(name,sex,area){
    person.call(this,name,sex);
    this.area=area;
    this.say=function(){
        alert(”chinese > my name is:”+this.name+” and sex:”+this.sex);
    }
}
chinese.prototype=new person();
chinese.prototype.from=function(){
    alert(”and from:”+this.area);
}
function person(name,sex){
    this.name=name;
    this.sex=sex;
    this.say=function(){
        alert(”my name is:”+this.name+” and sex:”+this.sex);
    }
}
person.prototype.saylove=function(){
    alert(”love”+this.name);
}

html:

<a href=”#ihao_say” class=”say” name=”ihao” sex=”male” area=”hangzhou”>ihao say</a>

<a href=”#tt_say” class=”say” name=”tt” sex=”female” area=”hz”>tt say</a>

 

btw:对象函数最好用原型(prototype)来写.

关于js面向对象:

javascript面向对象编程的学习(基础)

javascript面向对象编程的学习—对象继承

javascript对象编程规范(个人)

RSS feed for comments on this post. TrackBack URL

No Comments » Leave a comment

No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Popular Tags

Monthly Archives

iHao Friends

Site Meta