var promise=newPromise((resolve,reject)=>{//b 把需要执行的异步操作放在这里$.get("/getUser",res=>{//获取数据的异步操作已经执行完毕了,等待下一步的执行,通过执行resolve函数,告诉外界你可以执行下一步操作了//c、resolve(res)//而执行的下一步操作,其实就是写在then的回调函数中的})})//a、promise.then(res=>{//d、执行后续的操作console.log(res);})
asyncfunctionget(){console.log('开始执行');var res =awaittimer()console.log('执行结束:',res);}functiontimer(){returnnewPromise((resolve,reject)=>{setTimeout(()=>{resolve("你好");},1000)})}get();
//父类classPerson{constructor(name){this.name=name;}}//Student类继承自Person类classextends Person {//构造方法constructor(name,grade){//规定:必须调用父类构造方法,如果不调用就会报错super(name);//调用父类构造方法,从而给子类的实例添加了name属性this.grade=grade;}}
//b.jsimport common from"common.js"console.log( common.name )//"abc"
模块有多个导出
//person.jsexportconst jim ={ country :"France"}exportconst tony ={ color:"gray"}//默认的导出exportdefault{ name:"abc"}
//index.jsimport person ,{ jim , tony }from"person.js"//person:{ name:"abc" }//jim:{ country :"France" }//tony:{ color:"gray" }
模块导入导出取别名
js//person.jsexport const tOny= { color:"gray" }export { tony as Tony }//index.jsimport { Tony } from "person.js"import { Tony as man} from "person.js"console.log(man) //{ color:"gray" }