全国服务热线:400-603-3310 广州热线:020-85201720   网站专线:020-85201717

专题中心 联系我们

广州网站建设 网站制作 网站设计公司 广州腾虎网络科技有限公司

WHAT'S NEW?

新闻动态

致力提供国内性价比高的建站资讯

当前位置: > 腾虎新闻 > 网站优化 >

java 代码优化

腾虎网络:2010-05-05  阅读数:  分享到:
一、字符串的连接
  通常我们进行字符串连接是这样的:
   var veryLongMessage =
  
‘This is a long string that due to our strict line length limit of’ +
  
maxCharsPerLine +
  
‘ characters per line must be wrapped. ‘ +
  
percentWhoDislike +
  
‘% of engineers dislike this rule. The line length limit is for ‘ +
  
‘ style purposes, but we don’t want it to have a performance impact.’ +
  
‘ So the question is how should we do the wrapping?’;
  

  可以用如下的数字代替:
   var veryLongMessage =
  
['This is a long string that due to our strict line length limit of',
  
maxCharsPerLine,
  
' characters per line must be wrapped. ',
  
percentWhoDislike,
  
'% of engineers dislike this rule. The line length limit is for ',
  
' style purposes, but we don't want it to have a performance impact.',
  
' So the question is how should we do the wrapping?'
  
].join();
  

  二、通过助手函数生成字符串
  
   通过把字符串生成器传递到函数中来构造一个长字符串,要避免临时的String结果,例如,假设函数buildMenuItemHtml_ 需要用文字串(literal)和变量来构造String,并在内部使用了String构造器.而不是如下方式使用:
  
var strBuilder = [];
  
for (var i = 0, length = menuItems.length; i

官方微信

公司地址:广州市天河区福元南路4号达维商务中心2305
销售热线:020-85201720  85201717  或 400-603-3310

版权所有:广州腾虎网络科技有限公司
粤ICP备13073147号 

粤公网安备 44010602001101号