//类
class Person {
constructor(name,age,sex) {
this.name = name;
this.age = age;
this.sex = sex;
}
getName(){
return this.name;
}
getAge(){
return this.age;
}
}
let p1 =new Person('zhang',20,'nan');
console.log(p1.getAge());
//继承父类
class Student extends Person{
//构造函数
constructor(name,age,sex,school) {
super(name,age,sex);//继承父类的属性
this.school=school;
}
}
let s1 =new Student('zhang1',20,'nan','文化小学');
console.log(s1.school);//文化小学
//Json对象
console.log(typeof s1);//object
//对象转JSON字符串
let s1String =JSON.stringify(s1);
console.log(typeof s1String );//string
//JSON字符串转对象
let s1Obj = JSON.parse(s1String);
console.log(typeof s1Obj)//object
//包含js
// node 中 js 包含 用 var {解构} = require("./a")
// 前端JavaScript 中 用 import {解构} from "./a.js"
//a.js 中 需要暴露出内容 用export暴露
//暴露出类
export class Person{
}
//暴露出变量
export let a=55;
//暴露默认方法
export default function(){
//node接收 当前js 时
let fun = require('./a');
//fun();
//JavaScript 接收时
// import hh from "./a.js";
// hh() 直接调用
}