在Ionic 3中定义模型的正确方法 [英] Correct way of defining a model in Ionic 3

查看:59
本文介绍了在Ionic 3中定义模型的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ionic 3中使用吸气剂和吸气剂定义模型的正确方法是什么?

What is the correct way of defining a model in Ionic 3 with getters and setters?

我遵循了这个.

export class ItemModel{
    private _name: string;

    constructor(private n: string){
      this._name = n;
    }

    get name(): string
    {
        return this._name;
    }

    set name(name: string)
    {
        this._name = name;
    }
}

对吗?

在某些论坛中,提到需要使代码非常简短.那么这是否意味着使用getter和setter会以某种方式影响性能?

In some forums it was mentioned about a need to keep the code very short. So does that mean using getters and setters would affect the performance somehow?

推荐答案

打字稿本地支持访问器,可有效处理获取​​器和设置器的工作.您无需手动将它们定义为单独的方法.

Typescript supports accessors natively, which effectively handle the job of getters and setters. You don't need to manually define them as separate methods.

这篇关于在Ionic 3中定义模型的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆