账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    typescript类的问题?
    20
    0
    class Point {
        public x: any;
        public y: any
        constructor(x: any, y: any) {
            this.x = x;
            this.y = y
        }
    }
    
    let point = new Point(1, 2);
    console.log(point.x)
    class Point {
        constructor(public x: any, public y: any) { }
    }
    
    let point = new Point(1, 2);
    console.log(point.x)

    第一种写法我能理解,可是第二种是什么意思呢,在constructor的参数里加上public就不用在类里面声明属性了吗?就不用写public x: any;和this.x = x;了???
    这里面是什么原理呢?

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部