荣耀彩票代理

  • JS特效 http://chsp8.com/js/
  • 汇总篇关于日常适用JS特殊代码技巧集合

    发布日期:2019-01-30 08:35:00


      今天又到了分享时刻,我相信各位忠实的网友朋友们已经大概了解我们网站的日常运作了,我们网站会时不时地将一些集合和汇总总体的分析以后然后分享给各位小伙伴们,这是非常的珍贵的资讯哦,今天的内容是关于JS特效代码日常技巧的集合。

      1. 避免链式声明

    荣耀彩票代理  HOUGUO:KENENGYINRUQUANJUBIANLIANG

      //CUOWUDEXIEFA var a = b = 0;

      ZHEIDUANDAIMAZHONG,bSHIJISHANGBEISHENGMINGWEIQUANJUBIANLIANG。YINWEICAOZUOFUYOUXIANJISHISHICONGYOUWANGZUO,SUOYIGAIYUJUXIANGDANGYU:

      var a = (b = 0)

      CISHIbWEISHENGMINGJIUBEIZHIJIEFUZHI,SUOYIbCHENGLEQUANJUBIANLIANG

      2. DANYIvarYUANZE

      ZHEITIAOGUIZEDEYISISHI,BAHANSHUNEIBUDESUOYOUBIANLIANG,FANGDAODINGBUSHENGMING。BIRU:

      //SHILI function A(){ var a = 1, b = 2, c = a + b ; }

      YOUDIAN:

      BIANYUCHAZHAOHANSHUNEIBUSHIYONGDEJUBUBIANLIANG

    荣耀彩票代理  FANGZHIBIANLIANGWEIDINGYISHIJIUBEISHIYONG

      FANGZHIBIANLIANGSHENGMINGTISHENGHOUYINFADEWUJIE

      GUANYUDISANDIAN,ZHEILIJUGELIZISHUOMING:

      var x = 1; function A(){ console.log(x);//DIYICHUSHUCHU ,ZHUYIJIEGUO var x = 2; console.log(x);//DIERCHUSHUCHU 2,MEIWENTI }

    荣耀彩票代理  CONGDAIMASHANGKAN,DIERCHUSHUCHUKENDINGMEIWENTI,KENENGHUIYOURENRENWEIDIYICHUSHUCHUDESHI1,YINWEICISHIZAIHANSHUNEIBUHAIMEISHENGMINGBIANLIANGx,GENJUZUOYONGYULIAN,XIANGWAICENGCHAZHAODEHUA,xZHIWEI1。DANSHISHIJISHUCHUDEZHIYINGGAISHIundefined,YINWEIjsYUNXUZAIHANSHURENHEDIFANGSHENGMINGBIANLIANG,BINGQIEWULUNZAINALISHENGMINGDOUDENGTONGYUZAIDINGBUSHENGMING,ZHEIJIUSHISHENGMINGTISHENG。SUOYISHANGMIANDEDAIMAXIANGDANGYU:

      var x = 1; function A(){ var x;//TISHENGDAODINGBU console.log(x);//CISHIYISHENGMING WEIFUZHI x = 2;//FUZHI console.log(x); }

    荣耀彩票代理  3. SHIYONGforXUNHUANSHI,HUANCUNZHANGDUZHI

    技巧

      TONGCHANGYONGSHIYONGforXUNHUANBIANLISHUZUSHI,HUICAIYONGYIXIAXIEFA:

      for(var i = 0;i

    荣耀彩票代理  ZHEIDUANDAIMACUNZAIDEWENTIZAIYU,ZAIXUNHUANDEMEIGEDIEDAIBUZHOU,DOUBIXUFANGWENYICIarrDEZHANGDU。RUGUOarrSHIJINGTAISHUZHIHAIHAO,DANSHIWOMENZAISHIYONGjsSHIKENENGHUIPENGDAOarrSHIdomYUANSUDUIXIANG,YOUYUdomDUIXIANGZAIYEMIANXIASHIHUODONGDECHAXUN,ZHEIGEZHANGDUCHAXUNJIUXIANGDANGHAOSHI,

      //用len缓存长度值for(var i = 0,len = arr.length;i

      ANZHAOSHANGMIANDEDAIMA,WOMENZAIDIYICIHUOQUZHANGDUZHISHIJIUHUANCUNZHEIGEZHANGDUZHI,JIUKEYIBIMIANSHANGSHUWENTI。

    荣耀彩票代理  4. SHIYONGfor-inSHI,ZENGJIAhasOwnProperty()PANDUAN

      for-inTONGCHANGYONGLAIMEIJUDUIXIANGDESHUXINGHEFANGFA,DANSHIZHEIGEFANGFAHUIMEIJUFANWEIBAOKUODUIXIANGHEDUIXIANGDEYUANXINGDUIXIANG(DUIYUANXINGDUIXIANGBULEJIEDEKEYIKANKANWOZHIQIANXIEDEWENZHANGCHUANSONGMEN)CISHI,LIYONGhasOwnProperty()FANGFAKEYIBANGWOMENGUOLVCHUZHIZAIDUIXIANGBENSHENSHANGDESHUXINGHEFANGFA,HUOZHEZHIZAIYUANXINGLIANDESHUXINGHEFANGFA

    荣耀彩票代理  for(var key in obj){ if(obj.hasOwnProperty(key)){ // DUIXIANGBENSHENDESHUXINGHUOZHEFANGFA } else{ // YUANXINGLIANDESHUXINGHEFANGFA }}/* XIAMIANSHIYIGEJUTIDELIZI */ function A(name){ this.type = 'ALEI'; this.name = name || 'WEIMINGMING'}var a = new A('a');function B(name){ this.subtype = 'BLEI';}// JIANLIYUANXINGLIANB.prototype = a;B.prototype.sayHello = function(){}var b = new B();// BIANLISHUXINGfor(var key in b){ //DUIXIANGZISHENSHUXING if(b.hasOwnProperty(key)){ console.log('DUIXIANGZISHENDESHUXINGHUOFANGFA:'+key) } //SHANGSHUBIAODASHIDELINGYIZHONGXIEFA if(B.prototype.hasOwnProperty.call(b,key)){ console.log('DUIXIANGZISHENDESHUXINGHUOFANGFA:'+key) } else { console.log('YUANXINGLIANDESHUXINGHUOFANGFA:'+key) }}

    荣耀彩票代理  5. SHIYONG===DAITI==

      ZHEIGESUANSHIBIJIAOCHANGJIANDELE,YINWEIjsZAIZUOBIJIAOPANDUANSHI,HUIZHIXINGQIANGZHILEIXINGZHUANHUAN,BIRUfalse == 0FANHUItrueZHEIYANGDEQINGKUANG,SHIYONG===KEYIZHIXINGYANGEDEDENGJIABIJIAO,GENGYIYUYUEDUDAIMA(HOULAIYUEDUDERENJIUBUXUYAOPANDUANZHEIGESHIYILOUHAISHIGUYISHIYONGQIANGZHILEIXINGZHUANHUANJIANXIE)

    荣耀彩票代理  6. SHIYONGparseInt()SHI,DAISHANGDIERGECANSHU。

    荣耀彩票代理  parseInt()YONGYUCONGZIFUCHUANZHONGHUOQUSHUZHI,DIERGECANSHUDAIBIAOJINZHI,MORENSHI10。WOMENZAISHIYONGDESHIHOUKENENGXIGUANXINGHULVEZHEIGECANSHU,DANSHIZAIYIXIEQINGKUANGXIAHUIYOUWENTI:DANGZIFUCHUANDEKAITOUWEI0SHI,ZAIes3LIHUIBEIDANGZUOSHIBAJINZHI,es5LIMIANRENGRANDANGZUO10JINZHI,WEILEDAIMADEYIZHIXINGYIJIBIMIANBUBIYAODESHIWU,YINGGAIMEICISHIYONGSHIDOUDAISHANGCANSHU:

    荣耀彩票代理  var x = parseInt('089',10);//SHIYONGSHIDOUDAISHANGJINZHICANSHU

      7. DAKUOHAODESHIYONG

      DAKUOHAODESHIYONGZHUYAOSHI2GEFANGMIAN:

    荣耀彩票代理  DI1,BUYAOSHENGLVEDAKUOHAO,JISHIKEYIHULVE,BIRU:

    荣耀彩票代理  for(var i =1;i<10 ;i++) console.log(i) //CICHUYUANZESHANGKEYIHULVEDAKUOHAO

      SHANGSHUYUJUBINGMEIYOUWENTI,DANSHIRUGUOHOUQIHANSHUTINEIZENGJIALEQITAYUJUDESHIHOU,HENRONGYIWANGJIBUSHANGDAKUOHAO,YINCIJIANYIDOUDAISHANGDAKUOHAO;

      DI2,DAKUOHAODEBIXUGENZAIQIANYIGEYUJUDETONGYIXING

    荣耀彩票代理  ZHEIGEDIFANGWEISHENMEJIACULENI?YINWEIZHEIGEWENTIFEICHANGRONGYIBEIHULVE,TONGCHANGWOMENDOUJUEDEDAKUOHAOSHIGENZAIYUJUDETONGYIXINGHAISHIXIAYIXINGZHISHIXIGUANWENTI,DANSHISHIJISHANGBUSHIDE!KANXIAMIANZHEIGELIZI:

      function func(){ return { name:'xxx' }}var res = func()console.log(res)//SHUCHUundefined

      SHIBUSHIJUEDEHENQIGUAI,KANDAIMADIYIGANJUEYINGGAISHISHUCHUYIGEBAOHANnameSHUXINGDEDUIXIANG。QINGZHUYI,YOUYUjsDEFENHAOCHARUJIZHI:RUGUOYUJUMEIYOUSHIYONGFENHAOJIESHU,HUIZIDONGBUCHONGFENHAO,YINCISHANGMIANDEDAIMASHIJIXIANGDANGYURUXIAXIEFA:

      function func(){ return undefined;//ZIDONGCHARUFENHAO { name:'xxx' }}

    荣耀彩票代理  ZHENGQUEDEXIEFAYINGGAISHI:

    荣耀彩票代理  function func(){ return { name:'xxx' }}var res = func()console.log(res)//SHUCHU{name:'xxx'}

      BUZHIDAONIKANWANBENPIANWENZHANGYIHOUHAIYOUSHENMEYINANZHICHU,RUGUONIHAIYOURENHEDEWENTINIKEYILAIZIXUNWOMENDEGONGZUORENYUAN,TAMENHUIQINLIQINWEIDEBANGNIJIEJUEBINGQIEFENXIANGJIGEWEITONGYANGSHIZHEIZHONGWENTIDEXIAOHUOBANMEN,SUOYIQINGDAJIADUODUOZHICHIWOMENE。

    • 专题推荐

    次元立方 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
    本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规