zoukankan      html  css  js  c++  java
  • 微型的javascript REPL

    REPL(Read Eval Print Loop)是一种非常有用的工具,能让我们即时运行代码得到结果。虽然相比于firebug的控制台来说,这简直不值一提,但在个人博客中提供演示时它还是比较有用。

    下面是它的所有代码,包括html。

    <textarea style="100%" onkeyup="
      this.rows=(function(t){
        for (var i=0,h=1;i<t.length;i++) if (t.charAt(i) == '\n') h++;
        return h;
      })(this.value);
    ">
    //---------------------这是示例-----
    var now = new Date;
    var pad = function(num,  digits, radix, filling){
         num = num.toString(radix || 10);
         filling = filling || "0";
         while(num.length < digits){
             num= filling + num;
         }
         return num;
    }
    now = now.getFullYear()+"-"+pad(now.getMonth()+1,2)+"-"+pad(now.getDate(),2);
    p(now);
    //-----------------------------------
    </textarea><input type="submit" value="Eval" onclick="
      try{
        var o = this.nextSibling.nextSibling;
        var p = function(s){
          var e = document.createElement('p');
          e.appendChild(document.createTextNode(s));
          e.style.margin=0;
          o.appendChild(e);
        };
        (new Function('p',this.previousSibling.value))(p);
      }catch(e){
        alert(e)
      }
    "><input type="submit" value="Clear" onclick="
      this.nextSibling.innerHTML=''
    "><div style="border:inset 1px;padding:0.5em"></div>
    
  • 相关阅读:
    Centos7下thinkphp5.0环境配置
    win10蓝牙鼠标无法连接,需pin码
    thinkphp5自带workerman应用
    php文件加密(screw方式)
    centos修改ssh默认端口号的方法
    修改CentOS ll命令显示时间格式
    在线编辑器的原理简单示例
    [转载]提升SQLite数据插入效率低、速度慢的方法
    linux 客户机挂载vitualbox共享文件夹
    virtualbox linux客户机中安装增强功能包缺少kernel头文件问题解决
  • 原文地址:https://www.cnblogs.com/rubylouvre/p/1821871.html
Copyright © 2011-2022 走看看