每日3題
31 關于AMD、CMD規范區別說法正確的是?(多選)
A.AMD規范:是 RequireJS在推廣程序中對模塊定義的規范化產出的
B.CMD規范:是SeaJS 在推廣程序中對模塊定義的規范化產出的
C.CMD 推崇依賴前置;AMD 推崇依賴就近
D.CMD 是提前執行;AMD 是延遲執行
E.AMD性能好,因為只有用戶需要的時候才執行;CMD用戶體驗好,因為沒有延遲,依賴模塊提前執行了
32 以下代碼執行后,控制臺中的輸出內容為?
console.log(['1','2','3'].map(parseInt));
33 以下代碼執行后,控制臺中的輸出內容為?
const person = { name: "leo" };
function say(age) {
return `${this.name} is ${age}`;
}
console.log(say.call(person, 5));
console.log(say.bind(person, 5));
公眾號【今天也要寫bug】,每日更新前端面試題
答案及決議
31 答案 AB
- 考察 AMD 和 CMD 規范的了解
- C. CMD 推崇依賴就近,AMD 推崇依賴前置
D. CMD 是延遲執行,AMD 是提前執行
E. CMD 性能好,因為只有用戶需要的時候才執行,AMD 用戶體驗好,因為沒有延遲,依賴模塊提前執行了
32
// 答案:[1, NaN, NaN]
// 考察 map 方法和 parseInt 方法
// map 方法接受兩個引數:callback 和 thisArg
// callback 接受 3 個引數:currentValue、index、array
// parseInt 接受 2 個引數:string、radix
console.log(["1", "2", "3"].map(parseInt));
// 此處 parseInt 即為 callback
// 所以 parseInt 的兩個引數為:currentValue、index
// 等價于:
console.log(
["1", "2", "3"].map((currentValue, index) => parseInt(currentValue, index))
);
// currentValue='https://www.cnblogs.com/bidong/archive/2022/09/09/1'時,index=0,parseInt('1', 0)=1
// 涉及 parseInt 的特殊情況,當 parseInt 的第二個引數未指定或為0,第二個引數會自行推斷
// 根據推斷規則(詳見MDN),parseInt('1', 0)=parseInt('1', 10)=1
// currentValue='https://www.cnblogs.com/bidong/archive/2022/09/09/2'時,index=1,parseInt('2', 1)=NaN,radix 不等于0 且 不在 2~36 之間,則結果為 NaN
// currentValue='https://www.cnblogs.com/bidong/archive/2022/09/09/3'時,index=2,parseInt('3', 2)=NaN,因為 3 不是有效的 2 進制數
// 當 radix 是有效的值(2~32),待轉換的字串的每一位必須是有效的 radix 進制數
33
// 答案:leo is 5 和 一個函式
// 考察 call 和 bind 的區別
// call 和 apply 回傳的是指定 this 和引數后呼叫函式的值(是結果)
// bind 回傳的是指定 this 和引數后的函式的拷貝(是函式)
const person = { name: "leo" };
function say(age) {
return `${this.name} is ${age}`;
}
console.log(say.call(person, 5));
console.log(say.bind(person, 5));
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/506055.html
標籤:其他
