您当前的位置: 首页 >  Java

暂无认证

  • 0浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

JavaScript实现构造函数的封装

发布时间:2022-02-23 17:39:41 ,浏览量:0

function Car(brand, color, displacement) { this.brand = brand; this.color = color; this.displacement = displacement; this.info = function() { return `颜色为${this.color}的${this.brand},排量为${this.displacement}T。`; } } function Person({ brand, color, displacement, name, }) { Car.apply(this, [brand, color, displacement]); this.name = name; this.say = function() { console.log(`${this.name}买了一辆${this.info()}`); // 半晨买了一辆颜色为寒山暮紫的五菱星辰,排量为1.5T。 } } let infomation = { brand: '五菱星辰', color: '寒山暮紫', displacement: '1.5', name: '半晨', }, person = new Person(infomation); person.say(); 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.8676s