zoukankan      html  css  js  c++  java
  • js基础

    标题  状态  描述
      JS扩展方法  

     JS扩展方法与C#的扩展方法非常相似,也是可以链式调用的,也是通过对某个类的扩展写法来实现。这个东西非常好用,如果将预先写好的方法放到一个js里面引用的话,那么后面写js将非常有趣。

    <head>
        <title>测试JS扩展方法</title>
        <script type="text/javascript">
            // 合并多个空白为一个空白  
            String.prototype.ResetBlank = function() {        //对字符串扩展
                var regEx = /s+/g;  
                return this.replace(regEx, ' ');  
            };  
    
            window.onload = function()
            {
                var str = "你      在他想还好吗?";
                alert(str);
                str = str.ResetBlank();        //这样就能够调用了,跟C#的很像吧!
                alert(str);
            }
        </script>
    </head>
    
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
  • 相关阅读:
    eclipse中的项目如何打成war包
    【SVN】Please execute the 'Cleanup' command.
    2021.06.02模拟赛DP2
    2021.05.26模拟赛 DP1
    状压DP
    高斯消元
    矩阵快速幂
    2021.05.10讲题
    Luogu P2152[SDOI 2009]Super GCD
    Tarjan
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/4677167.html
Copyright © 2011-2022 走看看