var name = '小明';
var age = 20;
var message = '你好, ' + name + ', 你今年' + age + '岁了!';
alert(message);
es6写法
var name = '小明';
var age = 20;
var message = `你好, ${name}, 你今年${age}岁了!`;
alert(message);
要判断一个属性是否是xiaoming自身拥有的,而不是继承得到的,可以用hasOwnProperty()方法
var xiaoming = {
name: '小明'
};
xiaoming.hasOwnProperty('name'); // true
xiaoming.hasOwnProperty('toString'); // false
多请求数据合并 确保都请求成功才执行
var data1 = null;
var data2 = null;
function drawView() {
if (data1 && data2) {
// do someting.....
}
}
setTimeout(() => {
data1 = 1;
this.drawView();
}, 1000);
setTimeout(() => {
data2 = 2;
this.drawView();
}, 1500);
定时器是两个请求
promise.all方法 async await方法
async getFaceResult () {
try {
let location = await this.getLocation(this.phoneNum);
if (location.data.success) {
let province = location.data.obj.province;
let city = location.data.obj.city;
let result = await this.getFaceList(province, city);
if (result.data.success) {
this.faceList = result.data.obj;
}
}
} catch(err) {
console.log(err);
}
}