參數(shù) >= 3 時(shí),最好封裝在對(duì)象中傳遞才更優(yōu)雅。
-
關(guān)于頁(yè)面中異步函數(shù)調(diào)用,最好使用async/await。
-
標(biāo)簽上的行為操作,簡(jiǎn)單寫(xiě)
// 創(chuàng)建 or 更新 async saveHandler() { const data = this.state; if (data.status) { this.showToast('在線狀態(tài)不允許更改數(shù)據(jù),如需修改,請(qǐng)先下線該配置'); return; } const canSubmit = this.validata(); if (!canSubmit) { return; } const configs = this.formatData(); const self = this; try { const self = this; const type = state.get('isEditPage') ? 'update' : 'create'; const response = await ajax.post('/api/new/resource/configRule/create').send(Object.assign(data, { configs, businessKey, type })); if (!response) { throw new Error('網(wǎng)絡(luò)異常,請(qǐng)稍后重試'); } const res = response.body || {}; if (res.status !== 0) { if (res.error && res.error.message) { throw new Error(res.error.message); } throw new Error('網(wǎng)絡(luò)異常,請(qǐng)稍后重試'); } self.showToast('創(chuàng)建成功', 3000); window.location.href = `/resource/config/list/${businessKey}`; } catch (e) { self.showToast(e.toString(), 3000); } }
-
方法之間的調(diào)用
const logger = (...args) => { console.log(`[${new Date()}]`, ...args); } async function myAsyncFunc() { function promiseHelper() { return new Promise(resolve => setTimeout(() => resolve(123), 1000)); } const data = await promiseHelper(); logger("in myAsyncFunc, data:", data); return data; } function main() { myAsyncFunc() .then(data => { logger("in main, data:", data); }) .catch(console.error); } logger('start!'); main();
-
代碼規(guī)范
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 一 文件與組件命名 擴(kuò)展名: 使用.js作為js文件的擴(kuò)展名。如果同一個(gè)文件夾下有同名而不同作用的js文件,則通過(guò)...
- php-fig 1、FIG:PSR[0-4]代碼規(guī)范的得發(fā)明者、規(guī)范者,framework interoperab...
- iOS編程規(guī)范0規(guī)范 0.1前言 為??高產(chǎn)品代碼質(zhì)量,指導(dǎo)廣大軟件開(kāi)發(fā)人員編寫(xiě)出簡(jiǎn)潔、可維護(hù)、可靠、可 測(cè)試、高效...
- ESLint規(guī)范說(shuō)明1、工具簡(jiǎn)介ESLint是一個(gè)QA工具,用來(lái)避免低級(jí)錯(cuò)誤和統(tǒng)一代碼的風(fēng)格。ESLint被設(shè)計(jì)為...

