首页 > 其他 > 详细

面向对象写法模板

时间:2014-12-08 12:07:17      阅读:242      评论:0      收藏:0      [点我收藏+]
//构造函数
    function createPerson(name,age,work){ 
        this.name=name;
        this.age=age;
        this.work=work;
        //初始化
        this.inint();
    }
    //原型方法
    createPerson.prototype={
        //修正constructor
        constructor:createPerson,
        inint:function(){ 
            this.showMsg();
            this.sayHi();
        },
        showMsg:function(){ 
            //alert(‘我的名字是‘+this.name+‘,年龄‘+this.age+‘,‘+this.work);
        },
        sayHi:function(){ 
            //alert(‘hi!我是一个:‘+this.work);
        }
    }
    //调用
    var p1=new createPerson(‘tom‘,‘21‘,‘学生‘);
    var p2=new createPerson(‘ollie‘,‘27‘,‘web前端工程师‘);

 

面向对象写法模板

原文:http://www.cnblogs.com/ollie-sk8/p/4150682.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!