1 Star 0 Fork 0

math.most/js_study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
012.3类.js 601 Bytes
一键复制 编辑 原始数据 按行查看 历史
math.most 提交于 2021-11-08 07:44 +08:00 . 查漏补缺01
/**
* 类 class
*/
class User {
// 静态属性
static host = "http://www.baidu.com";
static _host = "https://www.souhu.com"; // 使用_自定义保护属性
constructor (name, age) {
this.name = name;
this.age = age;
}
getName() {
return this.name;
}
// 静态方法
static staticCreateFunc (...args) {
return new this(...args);
}
}
let user = new User("哇哈哈", 19);
console.log(user.name);
console.log(user.getName());
console.log(User.staticCreateFunc("可口可乐", 18)); // User { name: '可口可乐', age: 18 }
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mathmost/js_study.git
git@gitee.com:mathmost/js_study.git
mathmost
js_study
js_study
master

搜索帮助