javascript - 这两种在Javascript中创建构造函数的方式有什么区别?
问题描述
我一直在学习 javascript 中的 OOP,通过学习不同的教程,我了解到人们使用不同的语法来执行构造函数,这两种方式有区别吗?还有更多方法吗?
首先,使用类语法
class Fish {
constructor() {
this.head = 1,
this.eyes = 2
}
}
let whale = new Fish();
二、使用函数语法
function Human() {
this.head = 1,
this.arms = 2,
this.legs = 2,
this.fingers = 20
}
let joe = new Human();
解决方案
推荐阅读
- python - 如何在 Python 的 Apache-Beam DataFlow 中组合解析的文本文件?
- python - regexp_replace 的元组索引超出范围 - pyspark-sql
- python - 从多个图像中检测目标:从多个图像中提取检测到的边界框
- python - 在云服务器上托管 RASA NLU 模型
- environment-variables - 保存 Postman 环境变量无法正常工作?
- c# - Oracle.DataAccess.Client.OracleException:数据提供者内部错误(-3000)[System.String]
- python - 小写特定案例的列表,而不是其他案例
- javascript - 如何在javascript中以表单形式进行验证?
- azure - Azure AD JWT 令牌验证选项
- google-cloud-platform - 使用 Stackdriver 的 GoogleCloud 生产访问控制