pos机怎么办理tinc代码

pos机怎么办理tinc代码【徽同电15732660050】在 IT 产业的上古时代,流传着许多独行侠程序员们徒手写出操作系统、编程语言、浏览器等高难度软件的传说。随着行业的成熟,这些故事大多已经尘埃落定。但今天,我们有幸见证了一个正在进行中的年轻故事。这个故事的主人公,让世界上数以百万的人,用上了昂贵 Photoshop 软件的免费替代品。
一、变量
用有意义且常用的单词命名
// Bad:
const yyyymmdstr = moment().format(‘YYYY/MM/DD’);
// Good:
const currentDate = moment().format(‘YYYY/MM/DD’);
复制代码保持统一
对同一类型的变量使用相同的命名保持统一:
// Bad:
getUserInfo();
getClientData();
getCustomerRecord();
// Good:
getUser()
复制代码每个常量(全大写)都该命名
可以用 ESLint 检测代码中未命名的常量。
// Bad:
// 其他人知道 86400000 的意思吗?
setTimeout( blastOff, 86400000 );
// Good:
const MILLISECOND_IN_A_DAY = 86400000;
setTimeout( blastOff, MILLISECOND_IN_A_DAY );
复制代码避免无意义的命名
既然创建了一个 car 对象,就没有必要把它的颜色命名为 carColor。
// Bad:
const car = {
carMake: ‘Honda’,
carModel: ‘Accord’,
carColor: ‘Blue’
};
function paintCar( car ) {
car.carColor = ‘Red’;
}
// Good:
const car = {
make: ‘Honda’,
model: ‘Accord’,
color: ‘Blue’
};
function paintCar( car ) {
car.color = ‘Red’;
}
复制代码传参使用默认值
// Bad:
function createMicrobrewery( name ) {
const breweryName = name || ‘Hipster Brew Co.’;
// …
}
// Good:
function createMicrobrewery( name = ‘Hipster Brew Co.’ ) {
// …
}
复制代码二、函数
函数参数( 最好 2 个或更少 )
如果参数超过两个,建议使用 ES6 的解构语法,不用考虑参数的顺序。
// Bad:
function createMenu( title, body, buttonText, cancellable ) {
// …
}
// Good:
function createMenu( { title, body, buttonText, cancellable } ) {
// …
}
createMenu({
title: ‘Foo’,
body: ‘Bar’,
buttonText: ‘Baz’,
cancellable: true
});
复制代码一个方法只做一件事情
这是一条在软件工程领域流传久远的规则。严格遵守这条规则会让你的代码可读性更好,也更容易重构。如果违反这个规则,那么代码会很难被测试或者重用。
// Bad:
function emailClients( clients ) {
clients.forEach( client => {
const clientRecord = database.lookup( client );
if ( clientRecord.isActive() ) {
email( client );
}
});
}
// Good:
function emailActiveClients( clients ) {
clients
.filter( isActiveClient )
.forEach( email );
}
function isActiveClient( client ) {
const clientRecord = database.lookup( client );
return clientRecord.isActive();
}
复制代码函数名上体现它的作用
// Bad:
function addToDate( date, month ) {
// …
}
const date = new Date();
// 很难知道是把什么加到日期中
addToDate( date, 1 );
// Good:
function addMonthToDate( month, date ) {
// …
}
const date = new Date();
addMonthToDate( 1, date );
复制代码删除重复代码,合并相似函数
很多时候虽然是同一个功能,但由于一两个不同点,让你不得不写两个几乎相同的函数。
// Bad:
function showDeveloperList(developers) {
developers.forEach((developer) => {
const expectedSalary = developer.calculateExpectedSalary();
const experience = developer.getExperience();
const githubLink = developer.getGithubLink();
const data = {
expectedSalary,
experience,
githubLink
};
render(data);
});
}
function showManagerList(managers) {
managers.forEach((manager) => {
const expectedSalary = manager.calculateExpectedSalary();
const experience = manager.getExperience();
const portfolio = manager.getMBAProjects();
const data = {
expectedSalary,
experience,
portfolio
};
render(data);
});
}
// Good:
function showEmployeeList(employees) {
employees.forEach(employee => {
const expectedSalary = employee.calculateExpectedSalary();
const experience = employee.getExperience();
const data = {
expectedSalary,
experience,
};
switch(employee.type) {
case ‘develop’:
data.githubLink = employee.getGithubLink();
break
case ‘manager’:
data.portfolio = employee.getMBAProjects();
break
}
render(data);
})
}
复制代码使用 Object.assign 设置默认属性
// Bad:
const menuConfig = {
title: null,
body: ‘Bar’,
buttonText: null,
cancellable: true
};
function createMenu(config) {
config.title = config.title || ‘Foo’;
config.body = config.body || ‘Bar’;
config.buttonText = config.buttonText || ‘Baz’;
config.cancellable = config.cancellable !== undefined ? config.cancellable : true;
}
createMenu(menuConfig);
// Good:
const menuConfig = {
title: ‘Order’,
// 不包含 body
buttonText: ‘Send’,
cancellable: true
};
function createMenu(config) {
config = Object.assign({
title: ‘Foo’,
body: ‘Bar’,
buttonText: ‘Baz’,
cancellable: true
}, config);
// config : {title: “Order”, body: “Bar”, buttonText: “Send”, cancellable: true}
// …
}
createMenu(menuConfig);

猜你喜欢

转载自blog.csdn.net/a59612/article/details/93651579