Part1类特性:用类声明,本质是函数,类名建议大写。为了更好的学习该类,首先要掌握以下几个词:constructorconstructorsupersuperextendsinheritnewinstantiationinstance:classCatextendsAnimal{constructor(name,color){super(name);this.color=颜色;}say(){}}varc1=newCat("Littlecat","colorfulblack")part2模块化脚本标签的type类型改为module//定义一个获取api的方法functiongetApi(url){//返回一个promise实例returnnewPromise((resolve,reject)=>{$.ajax({url,dataType:"jsonp",success(res){//解析成功.thenresolve(res);},error(err){//拒绝解析.catchreject(err)}})})}varurl="https://apis.map.qq.com/ws/location/v1/ip?key=3BFBZ-ZKD3X-LW54A-ZT76D-E7AHO-4RBD5&output=jsonp"//调用函数传入urlgetApi(url)//resolve执行时.then获取resolve的结果.then(res=>{console.log(res);//将.city的文本设置为获取的城市varad_info=res.result.ad_info;$(".city").text(ad_info.city)varurl2=`http://wis.qq.com/weather/common?weather_type=observe|forecast_24h|air&source=pc&province=${ad_info.province}&city=${ad_info.city}`;//调用下一个getApi并返回下一个promise实例returngetApi(url2)})//在.then执行之后返回一个新的promise实例并且它还有一个.then方法(不是之前;).then(res=>{console.log("weather",res);varstr=`${res.data.observe.degree}°C,${res.data.observe.weather}`;$(".weather").text(str);})//获取控制台输出失败results.catch(err=>console.log(err))
