js实战案例--创建一个电脑对象

js实战案例–创建一个电脑对象

一、创建一个电脑对象,该对象要有颜色、重量、品牌、型号,可以看电影、听音乐、打游戏和敲代码。
<script>    
    function Computer(color,weight,id){
        this.color = color;
        this.weight = weight;
        this.id = id;
        this.sing = function(song){
            console.log(song);
        }
        this.see = function(movie){
            console.log(movie);
        }
        this.play = function(game){
            console.log(game);
        }
        this.study = function(it){
            console.log(it);
        }
    }
    var Lenovo  = new Computer('黄','100g','id:1');
    Lenovo.sing('可以听Jay的花海');
    Lenovo.see('可以看Jay的文字头-D');
    Lenovo.play('可以玩Jay喜欢玩的LOL');
    Lenovo.study('可以用来敲代码');
    console.log(Lenovo);
</script>

二、创建一个按钮对象,该对象需要包含宽、高、背景颜色和点击行为。
<script>    
    function Anniu(wide,high,back){
        this.wide = wide;
        this.high = high;
        this.back = back;
        this.chick = function(chick){
            console.log('写的代码点击就成功');
        }
    }
    var Lan = new Anniu('100px','200px','黄');
    Lan.chick(); 
    console.log(Lan);
</script>

三、创建一个车的对象,该对象要有重量、颜色、牌子、可以载人、拉货和耕田。
<script>    
    function Car(height,color,pinpai){
        this.height = height;
        this.color = color;
        this.pinpai = pinpai;
        this.zairen = function(zairen){
            console.log('这是一辆可以载人的车。');
        }
        this.lahuo = function(lahuo){
            console.log('这是一辆可以拉货的车。');
        }
        this.gengtian = function(gengtian){
            console.log('这是一辆可以耕田的车。');
        }
    }
    var Lan = new Car('200kg','white','凯迪拉克');
    Lan.zairen();
    Lan.lahuo();
    Lan.gengtian();
    console.log(Lan);
</script>

致谢观看的各位

  • 喜欢就点个关注♥
  • 个人企鹅:1074941198
  • 7
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值