Promise関数の記述
var test = new Promise(function(resolve,reject){
function test1 (){
var pOk;
var pCatch;
if(y){
resolve(pOK);
}else{
reject(pCatch);
}
}
});
test.then(function(data){
console.log(data); // Promise中返回得值
});
.call()関数
.call()関数は、呼び出し元の関数でこのポイントを変更するために使用されます。呼び出された関数のこれは、関数自体ではなく、彼を呼び出す関数を指します。
function Product(name, price) {
this.name = name;
this.price = price;
}
function Food(name, price) {
// 调用后product中的this指向的是Food而不是Product函数本身
Product.call(this, name, price);
this.category = 'food';
}
console.log(new Food('cheese', 5).name);
// 结果输出 ‘cheese’