Skip to content

xv700/rules

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 

Repository files navigation

编写前端代码标准

npm 引入方式标准
10.不许使用var变量声明,由let和const替代
20.禁止使用setInterval
30.禁用eval
代替eval函数

const evil = fn => {
    return new Function("return " + fn)();
}

40.自定义函数,参数不得超过两个,参数中不要使用回调函数(除非回调函数需要多次运行,例如XMLHttpRequest的进度回调函数),Promise替代,防止地狱回调
50.除去独立的库,不要重复定义同样功能的函数
60.语言包要独立,不允许每个文件出现文字字符,全部包含到一处(例如中文语言包,英文语言包)

70.UUID:可以产生一个随机的不重复的包含字符串和数字的函数

function UUID(){  
  return +new Date+Math.random().toString(36).substr(2);  
}  

0.FileReader的Promise写法

const toFileReader = (file,methods) => {
    const readmethods=({DataURL:"readAsDataURL",ArrayBuffer:"readAsArrayBuffer",BinaryString:"readAsBinaryString",readAsText:"readAsText"})[methods]||"readAsDataURL";

    return new Promise((resolve, reject)=>{

        const reader = new FileReader();
        reader.onload = res => {
            resolve(res.target.result);
        };
        (reader[readmethods])(file);
        reader.onerror = error => reject(error);
    })
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors