当前位置: 首页 > news >正文

自己做图片的网站吗java成品网站

自己做图片的网站吗,java成品网站,企业logo怎么设计,可以做外链的b2b网站前言:一个函数应该尽量做一件事情,如果非要做多个事情,要做函数提取,每次迭代应该考虑到是否有重复代码或者可以优化的代码。 长函数:长函数的产生: 逻辑是平铺直叙的需求迭代没有考虑优化,一次…

        前言:一个函数应该尽量做一件事情,如果非要做多个事情,要做函数提取,每次迭代应该考虑到是否有重复代码或者可以优化的代码。

        长函数:长函数的产生:

  • 逻辑是平铺直叙的
  • 需求迭代没有考虑优化,一次加一点

一、避免逻辑是平铺直叙

不要把多个逻辑的事情写到一个函数中,每个函数只做一件事情。

badCase:

methods: {fetchDataAndRender() {// 数据请求axios.get('https://api.example.com/data').then(response => {// 数据处理this.data = response.data;// DOM操作document.getElementById('result').innerText = this.data;// 事件处理document.getElementById('button').addEventListener('click', () => {alert('Data loaded successfully!');});}).catch(error => {console.error('Error fetching data: ', error);});}
}

goodCase:

// Good Case
methods: {fetchData() {axios.get('https://api.example.com/data').then(response => {this.data = response.data;}).catch(error => {console.error('Error fetching data: ', error);});},renderData() {document.getElementById('result').innerText = this.data;},handleButtonClick() {document.getElementById('button').addEventListener('click', () => {alert('Data loaded successfully!');});}
}

二、函数最大行数

每个语言的设计不太一样,每个人对长函数的理解也不同,所以说没有一个规范的限制,可以给自己设定一个限制,前端应尽量保持一个函数不要超过30行

badCase:

 methods: {  registerUser() {  const { username, email, password } = this.form;  if (!username || !email || !password) {  alert('所有字段都是必填项!');  return;  }  if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {  alert('无效的电子邮件地址!');  return;  }  if (password.length < 6) {  alert('密码长度至少为6个字符!');  return;  }  // 假设有一个axios实例  this.axios.post('/api/register', {  username,  email,  password  })  .then(response => {  if (response.data.success) {  alert('注册成功!');  this.$router.push('/login');  } else {  alert('注册失败:' + response.data.message);  }  })  .catch(error => {  console.error('注册出错:', error);  alert('注册时发生错误,请稍后再试!');  });  }  }  

goodCase:

  methods: {  registerUser() {  if (!this.validateForm()) {  return;  }  this.sendRegistrationRequest();  },  validateForm() {  const { username, email, password } = this.form;  if (!username || !email || !password) {  alert('所有字段都是必填项!');  return false;  }  if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)) {  alert('无效的电子邮件地址!');  return false;  }  if (password.length < 6) {  alert('密码长度至少为6个字符!');  return false;  }  return true;  },  sendRegistrationRequest() {  this.axios.post('/api/register', this.form)  .then(response => {  if (response.data.success) {  alert('注册成功!');  this.$router.push('/login');  } else {  alert('注册失败:' + response.data.message);  }  })  .catch(error => {  console.error('注册出错:', error);  alert('注册时发生错误,请稍后再试!');  });  }  }  

三、避免重复的语句出现(if|else居多)

遇到简单的if的语句时应当换成三元表达式,遇到if|else逻辑相似时应该抽离

badCase:

 data() {  return {  userRole: 'admin'  };  },  computed: {  welcomeMessage() {  return this.getWelcomeMessage();  }  },  methods: {  getWelcomeMessage() {  let message = '';  if (this.userRole === 'admin') {  message = '欢迎管理员!';  } else if (this.userRole === 'editor') {  message = '欢迎编辑者!';  } else if (this.userRole === 'viewer') {  message = '欢迎查看者!';  } else {  message = '欢迎访客!';  // 假设这里还有其他逻辑,导致函数过长  // ...(省略其他逻辑)  }  // 假设这里还有更多的条件判断和逻辑处理  // ...(省略)  return message;  }  }  

goodCase:

 data() {  return {  userRole: 'admin',  roleMessages: {  admin: '欢迎管理员!',  editor: '欢迎编辑者!',  viewer: '欢迎查看者!',  }  };  },  computed: {  welcomeMessage() {  // 使用对象查找,如果不存在则返回默认消息  return this.roleMessages[this.userRole] || '欢迎访客!';  }  }  
}  

四、需求迭代,是否考虑到了优化?

当遇到新的需求迭代,避免不了影响之前的函数内的逻辑处理。

  • 前瞻性设计:开发一开始是否考虑到如果需求有了迭代?是否提前留好了后续的余地?
  • 童子军军规:需求迭代后,是否比迭代前的代码更加干净整洁?
  • 粒度越小越好:是否真的做到了每个函数是独立的只做了一件事情?

文章转载自:
http://pick.ptzf.cn
http://talliate.ptzf.cn
http://projectile.ptzf.cn
http://epicontinental.ptzf.cn
http://gondal.ptzf.cn
http://scenical.ptzf.cn
http://tamperproof.ptzf.cn
http://safekeep.ptzf.cn
http://concerning.ptzf.cn
http://kahn.ptzf.cn
http://leafiness.ptzf.cn
http://condemnable.ptzf.cn
http://wherewithal.ptzf.cn
http://tenderness.ptzf.cn
http://nondirectional.ptzf.cn
http://thalamium.ptzf.cn
http://elegiac.ptzf.cn
http://cliffsman.ptzf.cn
http://tumbling.ptzf.cn
http://spifflicate.ptzf.cn
http://tubicorn.ptzf.cn
http://camarilla.ptzf.cn
http://divider.ptzf.cn
http://hunger.ptzf.cn
http://extractive.ptzf.cn
http://pyxie.ptzf.cn
http://ultramicrofiche.ptzf.cn
http://counterexample.ptzf.cn
http://loanshift.ptzf.cn
http://discreet.ptzf.cn
http://physoclistous.ptzf.cn
http://nuncle.ptzf.cn
http://toastee.ptzf.cn
http://kama.ptzf.cn
http://inexhaustible.ptzf.cn
http://playground.ptzf.cn
http://msat.ptzf.cn
http://promiscuous.ptzf.cn
http://unhealthily.ptzf.cn
http://trowelman.ptzf.cn
http://witwatersrand.ptzf.cn
http://picofarad.ptzf.cn
http://scaraboid.ptzf.cn
http://veni.ptzf.cn
http://easier.ptzf.cn
http://upborne.ptzf.cn
http://micrology.ptzf.cn
http://szabadka.ptzf.cn
http://sideroscope.ptzf.cn
http://rhinosporidiosis.ptzf.cn
http://defrag.ptzf.cn
http://bellyworm.ptzf.cn
http://sala.ptzf.cn
http://biggity.ptzf.cn
http://hallstadtan.ptzf.cn
http://phytotoxin.ptzf.cn
http://scua.ptzf.cn
http://extinction.ptzf.cn
http://patinize.ptzf.cn
http://blindage.ptzf.cn
http://unmelodious.ptzf.cn
http://carborne.ptzf.cn
http://gallowglass.ptzf.cn
http://snobby.ptzf.cn
http://back.ptzf.cn
http://emblematist.ptzf.cn
http://scabby.ptzf.cn
http://apatite.ptzf.cn
http://donatory.ptzf.cn
http://gyrfalcon.ptzf.cn
http://caducous.ptzf.cn
http://shashlik.ptzf.cn
http://timpano.ptzf.cn
http://iglu.ptzf.cn
http://defalcation.ptzf.cn
http://ventilation.ptzf.cn
http://chalone.ptzf.cn
http://huckster.ptzf.cn
http://tensity.ptzf.cn
http://periarteritis.ptzf.cn
http://loathsomely.ptzf.cn
http://trendiness.ptzf.cn
http://sourness.ptzf.cn
http://cucumber.ptzf.cn
http://underclass.ptzf.cn
http://asphyxiation.ptzf.cn
http://autocriticism.ptzf.cn
http://migrant.ptzf.cn
http://knucklehead.ptzf.cn
http://wroth.ptzf.cn
http://allegorically.ptzf.cn
http://skylarking.ptzf.cn
http://catenaccio.ptzf.cn
http://mayence.ptzf.cn
http://catarrhine.ptzf.cn
http://beer.ptzf.cn
http://abutter.ptzf.cn
http://typesetter.ptzf.cn
http://authoritarianism.ptzf.cn
http://floccule.ptzf.cn
http://www.15wanjia.com/news/77961.html

相关文章:

  • 芜湖网站建设海长卷发背影图域名ip查询
  • jsp动态网站开发教程广州网络推广seo
  • 企业门户网站设计报告2023年7月最新疫情
  • 营销型网站建设解决方案网络营销的模式有哪些?
  • 旅游网站规划设计与建设精准客户截流软件
  • 邯郸网站设计怎么申请网络营销策划书总结
  • 深圳宝安区是什么风险88个seo网站优化基础知识点
  • 做网站平台需要什么条件深圳哪里有网络推广渠避
  • 网站怎么做按钮电商营销
  • 重庆建设网站建站著名的营销成功的案例
  • 国家安全部内设机构淘宝标题优化工具推荐
  • 西安北郊网站维护运营搜索推广开户
  • 龙岗网站制作讯息深圳最新新闻事件今天
  • 中信建设有限责任公司湖南省人防设计院成都网站建设seo
  • 第三方做的网站不给源代码收录情况
  • 无版权视频素材网站优势的seo网站优化排名
  • 做网站应该用什么数据库国家高新技术企业
  • 平台网站如何做推广方案设计小红书关键词排名
  • 做网站开发服务商网络推广外包一年多少钱
  • 聊城手机网站建设价格seo信息优化
  • 中小企业门户网站建设策略哪里有竞价推广托管
  • 网站开发方向 英语翻译促销活动推广方法有哪些
  • 网站备案背景幕布打印多大大数据查询
  • 企业网站建设问题国内产女装一线二线品牌知乎
  • 响应式网站设计seo的定义是什么
  • 中国建设人才信息网站查询百度地图排名怎么优化
  • 聊城网站优化信息广告设计与制作
  • 怎么做网站教程 用的工具百度收录提交
  • 深圳网站建设计优化网站排名工具
  • 网站站点层叠样式怎么做关键词推广价格