1 Star 0 Fork 0

Liudatian/hm-toutiao-mobile-128

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test.html 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// Promise相关API
// Promise
// p.then
// p.catch
// Promise.resolve() 把数据包装为Promise对象并且得到正确结果
// Promise.reject() 把错误数据包装为Promise对象并且得到异常结果
function getResult() {
return new Promise(function (resolve, reject) {
setTimeout(() => {
resolve('hello')
}, 1000)
})
}
getResult().then(function (ret) {
console.log(ret)
// return 'nihao'
// return new Promise(function (resolve) {
// resolve('nihao')
// })
// return Promise.resolve('nihao')
// ---------------------------------------------
return Promise.reject('nihao')
// return new Promise(function (resolve, reject) {
// reject('nihao')
// })
}).then(function (ret) {
console.log(ret)
}).catch(function (err) {
console.log(err, '----------')
})
// Promise.resolve = function (param) {
// return new Promise(function (resolve) {
// resolve(param)
// })
// }
// Promise.reject = function (param) {
// return new Promise(function (resolve, reject) {
// reject(param)
// })
// }
</script>
</body>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liufuyue888/hm-toutiao-mobile-128.git
git@gitee.com:liufuyue888/hm-toutiao-mobile-128.git
liufuyue888
hm-toutiao-mobile-128
hm-toutiao-mobile-128
master

搜索帮助