相关疑难解决方法(0)

Javascript关闭性能

我已经在javascript中工作了一段时间,并且通常做这样的事情只是为了缓存在深层结构或"命名空间"中声明的函数的属性值

//global scope
(function ($, lib) {
  //function scope 1
  var format = lib.format, // instead of calling lib.format all the time just call format
    touch = lib.pointer.touch, //instead of calling lib.pointer.touch each time just touch
    $doc = $(document),
    log = logger.log; //not console log...


  $doc.on('app:ready', function () {
    //function scope 2
    $doc.on('some:event', function (e) {
      //function scope 3
      //use the cached variables
      log(format('{0} was triggered on the $doc object', e.type);
    });

    $doc.on(touch, function (e) {
      //function scope 3
      log(format('this …
Run Code Online (Sandbox Code Playgroud)

javascript performance closures

15
推荐指数
1
解决办法
4226
查看次数

标签 统计

closures ×1

javascript ×1

performance ×1