小编Ada*_*das的帖子

JavaScript 中的类与函数构造函数

背景:C# 开发人员最近深入研究 javascript

以下是在 JavaScript 中创建对象的两种方法。它们之间有什么区别,创建对象时我应该使用/优先考虑哪种方法,为什么?

class John {
    constructor(name, birth, height) {
        this.name = name;
        this.birth = birth;
        this.height = height;} }

var Person = function(name, birth, height) {
    this.name = name;
    this.birth = birth;
    this.height = height;}
Run Code Online (Sandbox Code Playgroud)

javascript

2
推荐指数
1
解决办法
2303
查看次数

标签 统计

javascript ×1