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>
    
  • 相关阅读:
    0x55 环形与后效性问题
    0x54 树形DP
    0x53 区间DP
    0x52 背包
    0x51 线性DP
    poj1015 Jury Compromise
    973、863计划取消 国家重点研发计划启动
    中科院院士陈仙辉回母校:英雄不问出处 成功要靠努力和实力来实现
    Resume (Curriculum Vitae)
    阅读linux内核代码的工具-- Source Insight
  • 原文地址:https://www.cnblogs.com/rubylouvre/p/1821871.html
Copyright © 2011-2022 走看看