function want() {
console.log("这是你想要执行的代码");
}
function fn(want) {
console.log("这里表示执行的一大段代码");
// 返回promise对象
return new Promise(function(resolve, reject) {
if (typeof want == "function") {
resolve(want);
} else {
reject("TypeError:" + want + "不是一个函数");
}
});
}
fn(want).then(function(want) {
want();
});
fn("1234").catch(function(err) {
console.log(err);
});