es6之类与对象
2024-10-02 01:14:46
一、类的定义
class Parent{
constructor(name="mukewang"){
this.name=name;
}
} let v_parant=new Parent("v");
console.log("constructor",v_parant);
类的继承
// extends 用于继承父类
//继承
class Parent{
constructor(name="mukewang"){
this.name=name;
}
} class Child extends Parent{ } console.log("extend", new Child()); //继承传递参数
//super必须放在设置改变参数的前面
{
class Parent{
constructor(name="mukewang"){
this.name=name;
}
} class Child extends Parent{
constructor(name="child"){
super(name);
this.type="child"
}
} console.log("extend", new Child("hello"));
}
get 、set 方法
//getter,setter
class Parent{
constructor(name="mukewang"){
this.name=name;
}
get longName(){
return "mk"+this.name
}
set longName(value){
this.name=value;
}
} let v=new Parent();
console.log("getter",v.longName);
v.longName="hello"
console.log("getter",v.longName);
静态方法
//静态方法
class Parent{
constructor(name="numewang"){
this.name=name;
} static tell(){
console.log("tell");
}
}
Parent.tell(); //静态属性
class Parent{
constructor(name="numewang"){
this.name=name;
} static tell(){
console.log("tell");
}
} Parent.type="test";
console.log("静态属性",Parent.type);
}
最新文章
- hdu5438 Ponds dfs 2015changchun网络赛
- Angular JS中的依赖注入
- (新人的第一篇博客)树状数组中lowbit(i)=i&;(-i) 的简单文字证明
- 【MySQL】MySQL复制表结构、表数据
- HDU 5059 Harry And Biological Teacher
- 批量创建客户主数据函数SD_CUSTOMER_MAINTAIN_ALL
- (转)解决png图片在IE6下不透明的方法
- I题 - A+B for Input-Output Practice (VIII)
- Nginx教程(四) Location配置与ReWrite语法
- C#泛型集合之List
- Caffe + Ubuntu 15.04 + CUDA 7.0 安装以及配置
- 幽灵自建的html5 的模板文件!
- MySQL服务无法启动 3534
- 第三章 jQuery总结 参考文本
- Java笔记一JAVA安装环境变量配置
- [leetcode]3. Longest Substring Without Repeating Characters无重复字母的最长子串
- python模块分析之logging日志(四)
- Linux 命令locate
- def chi(*food,**kw):
- mongodb lock 出毛病时解决方法