promise.
resolve(2
).finally
((res)
=>).
then
(res =>
)
const p=
[new
promise
((resolved, rejected)
=>),
newpromise
((resolved, rejected)
=>),
]promise.
all(p)
.then
((result)
=>).
catch
((err)
=>
);
const test =
[new
promise
((resolved, rejected)
=>),
newpromise
((resolved, rejected)
=>).
catch
(err =>)]
promise.
all(test)
.then
((result)
=>).
catch
((err)
=>
);
const test =
[new
promise
((resolved, rejected)
=>),
newpromise
((resolved, rejected)
=>)]
promise.
allsettled
(test)
.then
((result)
=>
,//
// ]})
.catch
((err)
=>
);
promise.
resolve
('foo'
)// 等價於
newpromise
(resolve =>
resolve
('foo'
))
引數是乙個 promise 例項
引數是乙個thenable
物件
// promise.resolve方法會將這個物件轉為 promise 物件,然後就立即執行thenable物件的then方法。
let thenable =};
let p1 = promise.
resolve
(thenable)
;// 執行thenable內的then方法
p1.then
(function
(value)
);
引數不是具有then方法的物件,或根本就不是物件const p = promise.
resolve
('hello');
p.then
(function
(s))
;// hello
不帶有任何引數const p = promise.
resolve()
;p.then
(function()
);
settimeout
(function()
,0);
promise.
resolve()
.then
(function()
);console.
log(
'one');
// one
// two
// three
const p = promise.
reject
('出錯了');
// 等同於
const p =
newpromise
((resolve, reject)
=>
reject
('出錯了'))
p.then
(null
,function
(s))
;
const thenable =};
promise.
reject
(thenable)
.catch
(e =>
)// true
JS查漏補缺1
1.function fn fn console.log typeof a undefined console.log typeof b number2.fn1 1 function fn1 fn2 報錯 var fn2 function 3.for infunction student stude...
Js查漏補缺 01
0x00 字串部分 使用 拼接字串與其他型別的資料,拼接出來的型別為字串 包括null與undefined 0x01 資料型別部分 typeof關鍵字可以獲取資料型別 例 typeof a parseint parsefloat 會去掉英文單詞,做動畫時可以用來去掉單位 使用時需注意首位不能為字母,...
Js查漏補缺 04
0x00 dom innertext 不識別html innerhtml 可以識別html,此外這兩個函式都能讀取元素內容 當無引數時 以上函式只能修改普通盒子的內容,像表單這種特殊標籤只能用value來修改 this在事件中指向的是事件函式的呼叫者 0x01 一些常用方法 listitems.pu...