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

js实战案例--创建一个电脑对象,第1张

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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1299038.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-10
下一篇2022-06-10

发表评论

登录后才能评论

评论列表(0条)

    保存