class
class Person {
name = "Eric"
age = 18
hobby () {
console.log('make a teacher')
}
}
let p = new Person()
class Persons {
constructor(name, age ,sex) {
this.name = name
this.age = age
this.sex = sex
}
hobbys(){
console.log(`${this.name}的爱好是...`)
}
}
***
let p = new Person("Eric",18, "男")
class Children extends Persons {
}
let child = new Children('xiaoJun',8,'男')
child.name
child.hobbys()
class Children extends Persons {
constructor(name,age,sex, eat){
super(name, age , sex)
this.eat = eat
}
}
class Worker {
static user = "Eric"
static work(){
console.log(Worker.user + '说他的工作是教书')
}
}
Worker.work()
**
**
暴露和导出的方式
exports.username = 'admin'
exports.password = '123'
exports.obj = {
name : "Eric",
age:18,
sex: '男'
}
exports.login = {
username : "Eric",
password : 123
}
exports.fun = () => {
console.log('这是public1中的fun方法')
}
const public = require('./public1')
console.log(public);
cmd 命令行 node module.js 运行 ,可以看到暴露成功
let username = 'admin'
let password = '123'
let obj = {
name : "Eric",
age:18,
sex: '男'
}
let login = {
username : "Eric",
password : 123
}
let fun = () => {
console.log('这是public1中的fun方法')
}
module.exports = {
username,
password,
obj,
login,
fun
}
同module.js 运行文件,也可以看到运行成功。
const username = 'admin'
const password = '123'
const obj = {
name : "Eric",
age:18,
sex: '男'
}
const login = {
username : "Eric",
password : 123
}
const fun = () => {
console.log('这是public1中的fun方法')
}
export {
username,
password,
obj,
login,
fun
}
import a from './public3'
console.log(a);
**
const rect = {
x:0,
y:0,
fill:'red'
}
export default rect
import rect from './default'
console.log('rect',rect)
***