在类中函数之前的“get”关键字是什么 - JavaScript?
get 关键字可以用作 C#、Java 和其他技术中的 getter 函数。
我们在类中设置了一个带 get 的函数,如下所示 -
class Employee {
constructor(name) {
this.name = name;
}
get fullName() {
return this.name;
}
}示例
以下代码显示了 get 的示例 -
class Employee {
constructor(name) {
this.name = name;
}
get fullName() {
return this.name;
}
}
var employeeObject = new Employee("David Miller");
console.log(employeeObject.fullName);要运行以上程序,你需要使用以下命令 -
node fileName.js.
此处,我的文件名是 demo299.js。
输出
这将在控制台上产生以下输出 -
PS C:\Users\Amit\javascript-code> node demo299.js David Miller
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP