Skip to content

对于web端消除eval并保证效率的一点建议,以及相应写法的优化。 #81

@Gaubee

Description

@Gaubee

据我所测试,web端的document.write这个应该和直接引入<script >的效率无异把。
所以基于此处,我是建议之间编译整个脚本块,

//<script>
Wind(function(){//包裹整个代码域
  //可能而外需要做的就是判定Wind.compile是否在字符串中
  var hello = Wind.compile("async", function () {
    console.log("hello")
  };
})
//<script>

当然,如果真的是要预编译整个文档,我更推崇下面这种写法,更加优雅客观:

//<script>
Wind(function(){//包裹整个代码域
  //可能而外需要做的就是判定Wind.compile是否在字符串中
  var hello = function () {
    "using wind";
    console.log("hello")
  };
})
//<script>

这种写法就不用写一堆的判定了把,只要一些正则和字符串处理就OK了,更优雅的实现不是?@JeffreyZhao

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions