为了账号安全,请及时绑定邮箱和手机立即绑定

问:错误:意外的令牌。预期是构造函数、方法、访问器或属性。ts(1068)

问:错误:意外的令牌。预期是构造函数、方法、访问器或属性。ts(1068)

慕码人8056858 2023-06-15 16:16:51
我的代码向我显示此错误“意外的标记。预期是构造函数、方法、访问器或属性。ts(1068)class animal {constructor(especie,edad,color){    this.especie = especie;    this.edad = edad;    this.color = color;    this.info = `Soy un ${this.especie}, tengo ${this.edad}    y soy de color ${this.color}`;}this.verInfo = ()=>{    document.write(this.verInfo);}}错误显示在这个.verInfo中
查看完整描述

1 回答

?
炎炎设计

TA贡献1808条经验 获得超4个赞

你想重写它如下:


也许在这里阅读有关课程的信息。这是一个非常好的开始参考:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes


您也可以重命名animal为Animal.


   class Animal {

    constructor(especie,edad,color){

        this.especie = especie;

        this.edad = edad;

        this.color = color;

        this.info = `Soy un ${this.especie}, tengo ${this.edad}

        y soy de color ${this.color}`;

    }

    verInfo = () =>{

        document.write(this.verInfo);

    }

   }


查看完整回答
反对 回复 2023-06-15
  • 1 回答
  • 0 关注
  • 80 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信